Skip to content

Commit 6c631cc

Browse files
cmb69smalyshev
authored andcommitted
Fix #77821: Potential heap corruption in TSendMail()
`zend_string_tolower()` returns a copy (not a duplicate) of the given string, if it is already in lower case. In this case we must not not `zend_string_free()` both strings. The cleanest solution is to call ` zend_string_release()` on both strings, which properly handles the refcount.
1 parent 588db7c commit 6c631cc

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

win32/sendmail.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,9 @@ PHPAPI int TSendMail(char *host, int *error, char **error_message,
274274
}
275275

276276
if (!found) {
277-
if (headers_lc) {
278-
zend_string_free(headers_lc);
277+
if (headers) {
278+
zend_string_release(headers_trim);
279+
zend_string_release(headers_lc);
279280
}
280281
*error = W32_SM_SENDMAIL_FROM_NOT_SET;
281282
return FAILURE;
@@ -289,8 +290,8 @@ PHPAPI int TSendMail(char *host, int *error, char **error_message,
289290
efree(RPath);
290291
}
291292
if (headers) {
292-
zend_string_free(headers_trim);
293-
zend_string_free(headers_lc);
293+
zend_string_release(headers_trim);
294+
zend_string_release(headers_lc);
294295
}
295296
/* 128 is safe here, the specifier in snprintf isn't longer than that */
296297
if (NULL == (*error_message = ecalloc(1, HOST_NAME_LEN + 128))) {
@@ -308,8 +309,8 @@ PHPAPI int TSendMail(char *host, int *error, char **error_message,
308309
efree(RPath);
309310
}
310311
if (headers) {
311-
zend_string_free(headers_trim);
312-
zend_string_free(headers_lc);
312+
zend_string_release(headers_trim);
313+
zend_string_release(headers_lc);
313314
}
314315
if (ret != SUCCESS) {
315316
*error = ret;

0 commit comments

Comments
 (0)