Skip to content

Commit d8e866d

Browse files
committed
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 ea52706 commit d8e866d

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,15 +1600,24 @@ static void php_free_request_globals(void)
16001600
static ZEND_COLD void php_message_handler_for_zend(zend_long message, const void *data)
16011601
{
16021602
switch (message) {
1603-
case ZMSG_FAILED_INCLUDE_FOPEN:
1604-
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)));
1603+
case ZMSG_FAILED_INCLUDE_FOPEN: {
1604+
char *tmp = estrdup((char *) data);
1605+
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)));
1606+
efree(tmp);
16051607
break;
1606-
case ZMSG_FAILED_REQUIRE_FOPEN:
1607-
zend_throw_error(NULL, "Failed opening required '%s' (include_path='%s')", php_strip_url_passwd((char *) data), STR_PRINT(PG(include_path)));
1608+
}
1609+
case ZMSG_FAILED_REQUIRE_FOPEN: {
1610+
char *tmp = estrdup((char *) data);
1611+
zend_throw_error(NULL, "Failed opening required '%s' (include_path='%s')", php_strip_url_passwd(tmp), STR_PRINT(PG(include_path)));
1612+
efree(tmp);
16081613
break;
1609-
case ZMSG_FAILED_HIGHLIGHT_FOPEN:
1610-
php_error_docref(NULL, E_WARNING, "Failed opening '%s' for highlighting", php_strip_url_passwd((char *) data));
1614+
}
1615+
case ZMSG_FAILED_HIGHLIGHT_FOPEN: {
1616+
char *tmp = estrdup((char *) data);
1617+
php_error_docref(NULL, E_WARNING, "Failed opening '%s' for highlighting", php_strip_url_passwd(tmp));
1618+
efree(tmp);
16111619
break;
1620+
}
16121621
case ZMSG_MEMORY_LEAK_DETECTED:
16131622
case ZMSG_MEMORY_LEAK_REPEATED:
16141623
#if ZEND_DEBUG

0 commit comments

Comments
 (0)