Skip to content

Commit 35f1b0b

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fix segfaults after conversion from zval to zend_string params
2 parents 5ebe04d + 8b265fb commit 35f1b0b

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

ext/imap/php_imap.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3532,6 +3532,7 @@ bool _php_imap_mail(zend_string *to, zend_string *subject, zend_string *message,
35323532

35333533
ZEND_ASSERT(to && ZSTR_LEN(to) != 0);
35343534
ZEND_ASSERT(subject && ZSTR_LEN(subject) != 0);
3535+
ZEND_ASSERT(message);
35353536

35363537
#ifdef PHP_WIN32
35373538
char *tempMailTo;
@@ -3661,14 +3662,23 @@ bool _php_imap_mail(zend_string *to, zend_string *subject, zend_string *message,
36613662
}
36623663
sendmail = popen(INI_STR("sendmail_path"), "w");
36633664
if (sendmail) {
3664-
if (ZSTR_LEN(rpath) != 0) fprintf(sendmail, "From: %s\n", ZSTR_VAL(rpath));
3665+
if (rpath && ZSTR_LEN(rpath) != 0) {
3666+
fprintf(sendmail, "From: %s\n", ZSTR_VAL(rpath));
3667+
}
3668+
/* to cannot be a null pointer, asserted earlier on */
36653669
fprintf(sendmail, "To: %s\n", ZSTR_VAL(to));
3666-
if (ZSTR_LEN(cc) != 0) fprintf(sendmail, "Cc: %s\n", ZSTR_VAL(cc));
3667-
if (ZSTR_LEN(bcc) != 0) fprintf(sendmail, "Bcc: %s\n", ZSTR_VAL(bcc));
3670+
if (cc && ZSTR_LEN(cc) != 0) {
3671+
fprintf(sendmail, "Cc: %s\n", ZSTR_VAL(cc));
3672+
}
3673+
if (bcc && ZSTR_LEN(bcc) != 0) {
3674+
fprintf(sendmail, "Bcc: %s\n", ZSTR_VAL(bcc));
3675+
}
3676+
/* subject cannot be a null pointer, asserted earlier on */
36683677
fprintf(sendmail, "Subject: %s\n", ZSTR_VAL(subject));
3669-
if (headers != NULL) {
3678+
if (headers && ZSTR_LEN(headers) != 0) {
36703679
fprintf(sendmail, "%s\n", ZSTR_VAL(headers));
36713680
}
3681+
/* message cannot be a null pointer, asserted earlier on */
36723682
fprintf(sendmail, "\n%s\n", ZSTR_VAL(message));
36733683
ret = pclose(sendmail);
36743684

ext/imap/tests/bug77020.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ imap_mail('1', 1, NULL);
1010
?>
1111
--EXPECTF--
1212
Warning: imap_mail(): No message string in mail command in %s on line %d
13-
%A
13+
%S

0 commit comments

Comments
 (0)