Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Zend/tests/gh25639.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
GH-25639: UAF in report_class_fetch_error() when the autoloader frees the class name
--CREDITS--
dhg0x
--FILE--
<?php

spl_autoload_register(function ($cls) {
$GLOBALS['cls'] = null;
});

function test() {
global $cls;
$cls::method();
}

$cls = implode("", ["Undefined", "Class"]);
try {
test();
} catch (Throwable $e) {
echo $e->getMessage(), "\n";
}

?>
--EXPECT--
Class "UndefinedClass" not found
14 changes: 8 additions & 6 deletions Zend/zend_execute_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -1775,11 +1775,12 @@ zend_class_entry *zend_fetch_class(zend_string *class_name, uint32_t fetch_type)
break;
}

ce = zend_lookup_class_ex(class_name, NULL, fetch_type);
zend_string *name = zend_string_copy(class_name);
ce = zend_lookup_class_ex(name, NULL, fetch_type);
if (!ce) {
report_class_fetch_error(class_name, fetch_type);
return NULL;
report_class_fetch_error(name, fetch_type);
}
zend_string_release(name);
return ce;
}
/* }}} */
Expand Down Expand Up @@ -1809,11 +1810,12 @@ zend_class_entry *zend_fetch_class_with_scope(
EMPTY_SWITCH_DEFAULT_CASE()
}

ce = zend_lookup_class_ex(class_name, NULL, fetch_type);
zend_string *name = zend_string_copy(class_name);
ce = zend_lookup_class_ex(name, NULL, fetch_type);
if (!ce) {
report_class_fetch_error(class_name, fetch_type);
return NULL;
report_class_fetch_error(name, fetch_type);
}
zend_string_release(name);
return ce;
}

Expand Down
Loading