Skip to content

Commit d2018ef

Browse files
committed
Fixed bug #33116 (crash when assigning class name to global variable in __autoload).
1 parent 1a72341 commit d2018ef

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

Zend/tests/bug33116.phpt

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Bug #33116 (crash when assigning class name to global variable in __autoload)
3+
--FILE--
4+
<?php
5+
function __autoload($class)
6+
{
7+
$GLOBALS['include'][] = $class;
8+
eval("class DefClass{}");
9+
}
10+
11+
$a = new DefClass;
12+
print_r($a);
13+
print_r($GLOBALS['include']);
14+
?>
15+
--EXPECT--
16+
DefClass Object
17+
(
18+
)
19+
Array
20+
(
21+
[0] => DefClass
22+
)

Zend/zend_execute_API.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ ZEND_API int zend_lookup_class(char *name, int name_length, zend_class_entry ***
895895
{
896896
zval **args[1];
897897
zval autoload_function;
898-
zval class_name, *class_name_ptr = &class_name;
898+
zval *class_name_ptr;
899899
zval *retval_ptr;
900900
int retval;
901901
char *lc_name;
@@ -936,8 +936,9 @@ ZEND_API int zend_lookup_class(char *name, int name_length, zend_class_entry ***
936936

937937
ZVAL_STRINGL(&autoload_function, ZEND_AUTOLOAD_FUNC_NAME, sizeof(ZEND_AUTOLOAD_FUNC_NAME)-1, 0);
938938

939+
ALLOC_ZVAL(class_name_ptr);
939940
INIT_PZVAL(class_name_ptr);
940-
ZVAL_STRINGL(class_name_ptr, name, name_length, 0);
941+
ZVAL_STRINGL(class_name_ptr, name, name_length, 1);
941942

942943
args[0] = &class_name_ptr;
943944

@@ -961,6 +962,8 @@ ZEND_API int zend_lookup_class(char *name, int name_length, zend_class_entry ***
961962
retval = zend_call_function(&fcall_info, &fcall_cache TSRMLS_CC);
962963
EG(autoload_func) = fcall_cache.function_handler;
963964

965+
zval_ptr_dtor(&class_name_ptr);
966+
964967
zend_hash_del(EG(in_autoload), lc_name, name_length+1);
965968

966969
if (retval == FAILURE) {

0 commit comments

Comments
 (0)