Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ PHP NEWS
. Added array_first() and array_last(). (nielsdos)
. Fixed bug GH-18823 (setlocale's 2nd and 3rd argument ignores strict_types).
(nielsdos)
. Fixed exit code handling of sendmail cmd and added warnings.
(Jesse Hathaway)

- Streams:
. Fixed bug GH-16889 (stream_select() timeout useless for pipes on Windows).
Expand Down
6 changes: 6 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ PHP 8.5 UPGRADE NOTES
Sqlite3Stmt::EXPLAIN_MODE_EXPLAIN and
Sqlite3Stmt::EXPLAIN_MODE_EXPLAIN_QUERY_PLAN.

- Standard:
. mail() now returns the actual sendmail error and detects if the sendmail
process was terminated unexpectedly. In such cases, a warning is emitted
and the function returns false. Previously, these errors were silently
ignored. This change affects only the sendmail transport.

- XSL:
. The $namespace argument of XSLTProcessor::getParameter(),
XSLTProcessor::setParameter() and XSLTProcessor::removeParameter()
Expand Down
15 changes: 5 additions & 10 deletions Zend/zend_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ static zend_always_inline void zend_init_interned_strings_ht(HashTable *interned
ZEND_API void zend_interned_strings_init(void)
{
char s[2];
unsigned int i;
zend_string *str;

interned_string_request_handler = zend_new_interned_string_request;
interned_string_init_request_handler = zend_string_init_interned_request;
Expand All @@ -103,25 +101,22 @@ ZEND_API void zend_interned_strings_init(void)
zend_string_init_existing_interned = zend_string_init_existing_interned_permanent;

/* interned empty string */
str = zend_string_alloc(sizeof("")-1, 1);
ZSTR_VAL(str)[0] = '\000';
zend_empty_string = zend_new_interned_string_permanent(str);
zend_empty_string = zend_string_init_interned_permanent("", 0, true);
GC_ADD_FLAGS(zend_empty_string, IS_STR_VALID_UTF8);

s[1] = 0;
for (i = 0; i < 256; i++) {
for (size_t i = 0; i < 256; i++) {
s[0] = i;
zend_one_char_string[i] = zend_new_interned_string_permanent(zend_string_init(s, 1, 1));
zend_one_char_string[i] = zend_string_init_interned_permanent(s, 1, true);
if (i < 0x80) {
GC_ADD_FLAGS(zend_one_char_string[i], IS_STR_VALID_UTF8);
}
}

/* known strings */
zend_known_strings = pemalloc(sizeof(zend_string*) * ((sizeof(known_strings) / sizeof(known_strings[0]) - 1)), 1);
for (i = 0; i < (sizeof(known_strings) / sizeof(known_strings[0])) - 1; i++) {
str = zend_string_init(known_strings[i], strlen(known_strings[i]), 1);
zend_known_strings[i] = zend_new_interned_string_permanent(str);
for (size_t i = 0; i < (sizeof(known_strings) / sizeof(known_strings[0])) - 1; i++) {
zend_known_strings[i] = zend_string_init_interned_permanent(known_strings[i], strlen(known_strings[i]), true);
GC_ADD_FLAGS(zend_known_strings[i], IS_STR_VALID_UTF8);
}
}
Expand Down
36 changes: 31 additions & 5 deletions ext/standard/mail.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include "ext/date/php_date.h"
#include "zend_smart_str.h"

#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif

#ifdef HAVE_SYSEXITS_H
# include <sysexits.h>
#endif
Expand Down Expand Up @@ -562,6 +566,7 @@ PHPAPI bool php_mail(const char *to, const char *subject, const char *message, c
}

if (sendmail) {
int ret;
#ifndef PHP_WIN32
if (EACCES == errno) {
php_error_docref(NULL, E_WARNING, "Permission denied: unable to execute shell to run mail delivery binary '%s'", sendmail_path);
Expand All @@ -582,26 +587,47 @@ PHPAPI bool php_mail(const char *to, const char *subject, const char *message, c
fprintf(sendmail, "%s%s", hdr, line_sep);
}
fprintf(sendmail, "%s%s%s", line_sep, message, line_sep);
int ret = pclose(sendmail);
#ifdef PHP_WIN32
ret = pclose(sendmail);

#if PHP_SIGCHILD
if (sig_handler) {
signal(SIGCHLD, sig_handler);
}
#endif

#ifdef PHP_WIN32
if (ret == -1)
#else
int wstatus = pclose(sendmail);
#if PHP_SIGCHILD
if (sig_handler) {
signal(SIGCHLD, sig_handler);
}
#endif
/* Determine the wait(2) exit status */
if (wstatus == -1) {
php_error_docref(NULL, E_WARNING, "Sendmail pclose failed %d (%s)", errno, strerror(errno));
MAIL_RET(false);
} else if (WIFSIGNALED(wstatus)) {
php_error_docref(NULL, E_WARNING, "Sendmail killed by signal %d (%s)", WTERMSIG(wstatus), strsignal(WTERMSIG(wstatus)));
MAIL_RET(false);
} else {
if (WIFEXITED(wstatus)) {
ret = WEXITSTATUS(wstatus);
} else {
php_error_docref(NULL, E_WARNING, "Sendmail did not exit");
MAIL_RET(false);
}
}
#endif

#if defined(EX_TEMPFAIL)
if ((ret != EX_OK)&&(ret != EX_TEMPFAIL))
#elif defined(EX_OK)
if (ret != EX_OK)
#else
if (ret != 0)
#endif
#endif
{
php_error_docref(NULL, E_WARNING, "Sendmail exited with non-zero exit code %d", ret);
MAIL_RET(false);
} else {
MAIL_RET(true);
Expand Down
3 changes: 2 additions & 1 deletion ext/standard/tests/mail/gh10990.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ $from = '[email protected]';
$headers = ['From' => &$from];
var_dump(mail('[email protected]', 'Test', 'Test', $headers));
?>
--EXPECT--
--EXPECTF--
Warning: mail(): Sendmail exited with non-zero exit code 127 in %sgh10990.php on line %d
bool(false)
4 changes: 3 additions & 1 deletion ext/standard/tests/mail/mail_basic5.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ $message = 'A Message';
echo "-- failure --\n";
var_dump( mail($to, $subject, $message) );
?>
--EXPECT--
--EXPECTF--
*** Testing mail() : basic functionality ***
-- failure --

Warning: mail(): Sendmail exited with non-zero exit code 1 in %smail_basic5.php on line %d
bool(false)
4 changes: 3 additions & 1 deletion ext/standard/tests/mail/mail_variation1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ $subject = 'Test Subject';
$message = 'A Message';
var_dump( mail($to, $subject, $message) );
?>
--EXPECT--
--EXPECTF--
*** Testing mail() : variation ***

Warning: mail(): Sendmail exited with non-zero exit code 127 in %smail_variation1.php on line %d
bool(false)
22 changes: 22 additions & 0 deletions ext/standard/tests/mail/mail_variation3.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
Test mail() function : variation sendmail temp fail
--INI--
sendmail_path=exit 75
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == "WIN")
die("skip Won't run on Windows");
?>
--FILE--
<?php
echo "*** Testing mail() : variation ***\n";

// Initialise all required variables
$to = '[email protected]';
$subject = 'Test Subject';
$message = 'A Message';
var_dump(mail($to, $subject, $message));
?>
--EXPECT--
*** Testing mail() : variation ***
bool(true)
24 changes: 24 additions & 0 deletions ext/standard/tests/mail/mail_variation4.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
Test mail() function : variation sigterm
--INI--
sendmail_path="kill \$\$"
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == "WIN")
die("skip Won't run on Windows");
?>
--FILE--
<?php
echo "*** Testing mail() : variation ***\n";

// Initialise all required variables
$to = '[email protected]';
$subject = 'Test Subject';
$message = 'A Message';
var_dump(mail($to, $subject, $message));
?>
--EXPECTF--
*** Testing mail() : variation ***

Warning: mail(): Sendmail killed by signal %d (%s) in %smail_variation4.php on line %d
bool(false)
24 changes: 24 additions & 0 deletions ext/standard/tests/mail/mail_variation5.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
Test mail() function : variation non-zero exit
--INI--
sendmail_path="exit 123"
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == "WIN")
die("skip Won't run on Windows");
?>
--FILE--
<?php
echo "*** Testing mail() : variation ***\n";

// Initialise all required variables
$to = '[email protected]';
$subject = 'Test Subject';
$message = 'A Message';
var_dump(mail($to, $subject, $message));
?>
--EXPECTF--
*** Testing mail() : variation ***

Warning: mail(): Sendmail exited with non-zero exit code 123 in %smail_variation5.php on line %d
bool(false)