Skip to content

Commit 3a857b9

Browse files
committed
Merge branch 'PHP-5.4' into PHP-5.4.42
* PHP-5.4: add NEWS Fixed bug #68776 fix test
2 parents 2fa226f + f1ffb4b commit 3a857b9

File tree

4 files changed

+379
-2
lines changed

4 files changed

+379
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ PHP NEWS
1212
- Litespeed SAPI:
1313
. Fixed bug #68812 (Unchecked return value). (George Wang)
1414

15+
- Mail:
16+
. Fixed bug #68776 (mail() does not have mail header injection prevention for
17+
additional headers). (Yasuo)
18+
1519
- Postgres:
1620
. Fixed bug #69667 (segfault in php_pgsql_meta_data). (Remi)
1721

ext/dom/tests/DOMDocument_loadHTMLfile_error2.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ $result = $doc->loadHTMLFile("");
1515
assert('$result === false');
1616
$doc = new DOMDocument();
1717
$result = $doc->loadHTMLFile("text.html\0something");
18-
assert('$result === null');
18+
assert('$result === false');
1919
?>
2020
--EXPECTF--
2121
%r(PHP ){0,1}%rWarning: DOMDocument::loadHTMLFile(): Empty string supplied as input %s
2222

23-
%r(PHP ){0,1}%rWarning: DOMDocument::loadHTMLFile() expects parameter 1 to be a valid path, string given %s
23+
%r(PHP ){0,1}%rWarning: DOMDocument::loadHTMLFile(): Invalid file source %s

ext/standard/mail.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,44 @@ void php_mail_log_to_file(char *filename, char *message, size_t message_size TSR
221221
}
222222

223223

224+
static int php_mail_detect_multiple_crlf(char *hdr) {
225+
/* This function detects multiple/malformed multiple newlines. */
226+
size_t len;
227+
228+
if (!hdr) {
229+
return 0;
230+
}
231+
232+
/* Should not have any newlines at the beginning. */
233+
/* RFC 2822 2.2. Header Fields */
234+
if (*hdr < 33 || *hdr > 126 || *hdr == ':') {
235+
return 1;
236+
}
237+
238+
while(*hdr) {
239+
if (*hdr == '\r') {
240+
if (*(hdr+1) == '\0' || *(hdr+1) == '\r' || (*(hdr+1) == '\n' && (*(hdr+2) == '\0' || *(hdr+2) == '\n' || *(hdr+2) == '\r'))) {
241+
/* Malformed or multiple newlines. */
242+
return 1;
243+
} else {
244+
hdr += 2;
245+
}
246+
} else if (*hdr == '\n') {
247+
if (*(hdr+1) == '\0' || *(hdr+1) == '\r' || *(hdr+1) == '\n') {
248+
/* Malformed or multiple newlines. */
249+
return 1;
250+
} else {
251+
hdr += 2;
252+
}
253+
} else {
254+
hdr++;
255+
}
256+
}
257+
258+
return 0;
259+
}
260+
261+
224262
/* {{{ php_mail
225263
*/
226264
PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char *extra_cmd TSRMLS_DC)
@@ -266,6 +304,7 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
266304

267305
efree(tmp);
268306
}
307+
269308
if (PG(mail_x_header)) {
270309
const char *tmp = zend_get_executed_filename(TSRMLS_C);
271310
char *f;
@@ -281,6 +320,11 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
281320
efree(f);
282321
}
283322

323+
if (hdr && php_mail_detect_multiple_crlf(hdr)) {
324+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Multiple or malformed newlines found in additional_header");
325+
MAIL_RET(0);
326+
}
327+
284328
if (!sendmail_path) {
285329
#if (defined PHP_WIN32 || defined NETWARE)
286330
/* handle old style win smtp sending */

0 commit comments

Comments
 (0)