Skip to content

Commit 79bf39e

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix GH-7875: mails are sent even if failure to log throws exception
2 parents 655e578 + 478edcd commit 79bf39e

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ PHP NEWS
1818

1919
- Standard:
2020
. Fixed bug GH-7899 (Regression in unpack for negative int value). (Remi)
21+
. Fixed bug GH-7875 (mails are sent even if failure to log throws exception).
22+
(cmb)
2123

2224
06 Jan 2022, PHP 8.1.2RC1
2325

ext/standard/mail.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,10 @@ PHPAPI int php_mail(const char *to, const char *subject, const char *message, co
425425
efree(logline);
426426
}
427427

428+
if (EG(exception)) {
429+
MAIL_RET(0);
430+
}
431+
428432
if (PG(mail_x_header)) {
429433
const char *tmp = zend_get_executed_filename();
430434
zend_string *f;

ext/standard/tests/mail/gh7875.phpt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
GH-7875 (mails are sent even if failure to log throws exception)
3+
--INI--
4+
sendmail_path={MAIL:{PWD}/gh7875.mail.out}
5+
mail.log={PWD}/gh7875.mail.log
6+
--FILE--
7+
<?php
8+
function exception_error_handler($severity, $message, $file, $line) {
9+
if (!(error_reporting() & $severity)) {
10+
return;
11+
}
12+
throw new ErrorException($message, 0, $severity, $file, $line);
13+
}
14+
set_error_handler("exception_error_handler");
15+
16+
touch(__DIR__ . "/gh7875.mail.log");
17+
chmod(__DIR__ . "/gh7875.mail.log", 0444);
18+
19+
try {
20+
mail('[email protected]', 'Subject', 'Body', []);
21+
echo 'Not Reached';
22+
} catch (\Exception $e) {
23+
echo $e->getMessage(), PHP_EOL;
24+
var_dump(file_exists(__DIR__ . "/gh7875.mail.out"));
25+
}
26+
?>
27+
--CLEAN--
28+
<?php
29+
@chmod(__DIR__ . "/gh7875.mail.log", 0644);
30+
@unlink(__DIR__ . "/gh7875.mail.log");
31+
@unlink(__DIR__ . "/gh7875.mail.out");
32+
?>
33+
--EXPECTF--
34+
mail(%s): Failed to open stream: Permission denied
35+
bool(false)

0 commit comments

Comments
 (0)