Skip to content

Commit 30830bc

Browse files
committed
Fixed bug #69115 crash in mail
There were two issues - php_pcre_replace could be used directly and sbject_str could be NULL - the Windows sendmail variant was freeing something passed from the outside
1 parent 8f5676f commit 30830bc

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

ext/pcre/php_pcre.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,11 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *su
12211221
new_len = result_len + subject_len - start_offset;
12221222
if (new_len > alloc_len) {
12231223
alloc_len = new_len; /* now we know exactly how long it is */
1224-
result = zend_string_realloc(result, alloc_len, 0);
1224+
if (NULL != result) {
1225+
result = zend_string_realloc(result, alloc_len, 0);
1226+
} else {
1227+
result = zend_string_alloc(alloc_len, 0);
1228+
}
12251229
}
12261230
/* stick that last bit of string on our output */
12271231
memcpy(&result->val[result_len], piece, subject_len - start_offset);

ext/standard/tests/mail/bug69115.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Bug #69115 crash in mail (plus indirect pcre test)
3+
--FILE--
4+
<?php
5+
/* Just ensure it doesn't crash when trimming headers */
6+
$message = "Line 1\r\nLine 2\r\nLine 3";
7+
mail('[email protected]', 'My Subject', $message, "From: [email protected]");
8+
?>
9+
===DONE===
10+
--EXPECTF--
11+
%A
12+
===DONE===

win32/sendmail.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ PHPAPI int TSendMail(char *host, int *error, char **error_message,
292292
efree(RPath);
293293
}
294294
if (headers) {
295-
efree(headers);
296295
efree(headers_lc);
297296
}
298297
/* 128 is safe here, the specifier in snprintf isn't longer than that */

0 commit comments

Comments
 (0)