Skip to content

Commit daa38dd

Browse files
iluuu1994ramsey
authored andcommitted
Fix in-place modification of filename in php_message_handler_for_zend
php_strip_url_passwd modifies url in-place. We cannot assume from php_message_handler_for_zend that data is a temporary, modifiable string. Fixes oss-fuzz #64209 Closes phpGH-12733
1 parent 1fdcfa4 commit daa38dd

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ PHP NEWS
55
- Core:
66
. Fixed oss-fuzz #54325 (Use-after-free of name in var-var with malicious
77
error handler). (ilutov)
8+
. Fixed oss-fuzz #64209 (In-place modification of filename in
9+
php_message_handler_for_zend). (ilutov)
810

911
- DOM:
1012
. Fixed bug GH-12616 (DOM: Removing XMLNS namespace node results in invalid

Zend/tests/oss_fuzz_64209.phpt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
oss-fuzz #64209: Fix in-place modification of filename in php_message_handler_for_zend
3+
--FILE--
4+
<?php
5+
require '://@';
6+
?>
7+
--EXPECTF--
8+
Warning: require(://@): Failed to open stream: No such file or directory in %s on line %d
9+
10+
Fatal error: Uncaught Error: Failed opening required '://@' (include_path='%s') in %s:%d
11+
Stack trace:
12+
#0 {main}
13+
thrown in %s on line %d

main/main.c

+15-6
Original file line numberDiff line numberDiff line change
@@ -1585,15 +1585,24 @@ static void php_free_request_globals(void)
15851585
static ZEND_COLD void php_message_handler_for_zend(zend_long message, const void *data)
15861586
{
15871587
switch (message) {
1588-
case ZMSG_FAILED_INCLUDE_FOPEN:
1589-
php_error_docref("function.include", E_WARNING, "Failed opening '%s' for inclusion (include_path='%s')", php_strip_url_passwd((char *) data), STR_PRINT(PG(include_path)));
1588+
case ZMSG_FAILED_INCLUDE_FOPEN: {
1589+
char *tmp = estrdup((char *) data);
1590+
php_error_docref("function.include", E_WARNING, "Failed opening '%s' for inclusion (include_path='%s')", php_strip_url_passwd(tmp), STR_PRINT(PG(include_path)));
1591+
efree(tmp);
15901592
break;
1591-
case ZMSG_FAILED_REQUIRE_FOPEN:
1592-
zend_throw_error(NULL, "Failed opening required '%s' (include_path='%s')", php_strip_url_passwd((char *) data), STR_PRINT(PG(include_path)));
1593+
}
1594+
case ZMSG_FAILED_REQUIRE_FOPEN: {
1595+
char *tmp = estrdup((char *) data);
1596+
zend_throw_error(NULL, "Failed opening required '%s' (include_path='%s')", php_strip_url_passwd(tmp), STR_PRINT(PG(include_path)));
1597+
efree(tmp);
15931598
break;
1594-
case ZMSG_FAILED_HIGHLIGHT_FOPEN:
1595-
php_error_docref(NULL, E_WARNING, "Failed opening '%s' for highlighting", php_strip_url_passwd((char *) data));
1599+
}
1600+
case ZMSG_FAILED_HIGHLIGHT_FOPEN: {
1601+
char *tmp = estrdup((char *) data);
1602+
php_error_docref(NULL, E_WARNING, "Failed opening '%s' for highlighting", php_strip_url_passwd(tmp));
1603+
efree(tmp);
15961604
break;
1605+
}
15971606
case ZMSG_MEMORY_LEAK_DETECTED:
15981607
case ZMSG_MEMORY_LEAK_REPEATED:
15991608
#if ZEND_DEBUG

0 commit comments

Comments
 (0)