Skip to content

Commit d7daf81

Browse files
committed
Merge branch 'PHP-5.5' into PHP-5.6
* PHP-5.5: Move strlen() check to php_mail_detect_multiple_crlf() Fixed Bug #69874 : Can't set empty additional_headers for mail()
2 parents 7e97faa + 8f2e082 commit d7daf81

File tree

3 files changed

+88
-3
lines changed

3 files changed

+88
-3
lines changed

ext/standard/mail.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ void php_mail_log_to_file(char *filename, char *message, size_t message_size TSR
226226
static int php_mail_detect_multiple_crlf(char *hdr) {
227227
/* This function detects multiple/malformed multiple newlines. */
228228

229-
if (!hdr) {
229+
if (!hdr || !strlen(hdr)) {
230230
return 0;
231231
}
232232

@@ -321,7 +321,7 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
321321

322322
php_basename(tmp, strlen(tmp), NULL, 0,&f, &f_len TSRMLS_CC);
323323

324-
if (headers != NULL) {
324+
if (headers != NULL && *headers) {
325325
spprintf(&hdr, 0, "X-PHP-Originating-Script: %ld:%s\n%s", php_getuid(TSRMLS_C), f, headers);
326326
} else {
327327
spprintf(&hdr, 0, "X-PHP-Originating-Script: %ld:%s", php_getuid(TSRMLS_C), f);
@@ -429,7 +429,7 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
429429
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not execute mail delivery program '%s'", sendmail_path);
430430
#if PHP_SIGCHILD
431431
if (sig_handler) {
432-
signal(SIGCHLD, sig_handler);
432+
signal(SIGCHLD, sig_handler);
433433
}
434434
#endif
435435
MAIL_RET(0);

ext/standard/tests/mail/bug69874.phpt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
Bug #69874: Null addtional_headers does not send mail
3+
--INI--
4+
sendmail_path=tee mailBasic.out >/dev/null
5+
mail.add_x_header = Off
6+
--SKIPIF--
7+
<?php
8+
if(substr(PHP_OS, 0, 3) == "WIN")
9+
die("skip Won't run on Windows");
10+
?>
11+
--FILE--
12+
<?php
13+
/* Prototype : int mail(string to, string subject, string message [, string additional_headers [, string additional_parameters]])
14+
* Description: Send an email message
15+
* Source code: ext/standard/mail.c
16+
* Alias to functions:
17+
*/
18+
19+
echo "*** Testing mail() : send email without additional headers ***\n";
20+
21+
// Initialise all required variables
22+
$to = 'user@company.com';
23+
$subject = 'Test Subject';
24+
$message = 'A Message';
25+
26+
$outFile = "mailBasic.out";
27+
@unlink($outFile);
28+
29+
var_dump( mail($to, $subject, $message) );
30+
echo file_get_contents($outFile);
31+
unlink($outFile);
32+
33+
?>
34+
===DONE===
35+
--EXPECTF--
36+
*** Testing mail() : send email without additional headers ***
37+
bool(true)
38+
To: user@company.com
39+
Subject: Test Subject
40+
41+
A Message
42+
===DONE===
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
Bug #69874: Null addtional_headers does not send mail
3+
--INI--
4+
sendmail_path=tee mailBasic.out >/dev/null
5+
mail.add_x_header = On
6+
--SKIPIF--
7+
<?php
8+
if(substr(PHP_OS, 0, 3) == "WIN")
9+
die("skip Won't run on Windows");
10+
?>
11+
--FILE--
12+
<?php
13+
/* Prototype : int mail(string to, string subject, string message [, string additional_headers [, string additional_parameters]])
14+
* Description: Send an email message
15+
* Source code: ext/standard/mail.c
16+
* Alias to functions:
17+
*/
18+
19+
echo "*** Testing mail() : send email without additional headers ***\n";
20+
21+
// Initialise all required variables
22+
$to = 'user@company.com';
23+
$subject = 'Test Subject';
24+
$message = 'A Message';
25+
26+
$outFile = "mailBasic.out";
27+
@unlink($outFile);
28+
29+
var_dump( mail($to, $subject, $message, '') );
30+
echo file_get_contents($outFile);
31+
unlink($outFile);
32+
33+
?>
34+
===DONE===
35+
--EXPECTF--
36+
*** Testing mail() : send email without additional headers ***
37+
bool(true)
38+
To: user@company.com
39+
Subject: Test Subject
40+
X-PHP-Originating-Script: %d:bug69874_2.php
41+
42+
A Message
43+
===DONE===

0 commit comments

Comments
 (0)