Skip to content

Commit ccd41e0

Browse files
committed
Fixed bug #97599 (coredump in set_error_handler)
1 parent bfcee2c commit ccd41e0

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ PHP NEWS
33
?? ??? ????, PHP 7.4.7
44

55
- Core:
6+
. Fixed bug #97599 (coredump in set_error_handler). (Laruence)
67
. Fixed bug #79566 (Private SHM is not private on Windows). (cmb)
78
. Fixed bug #79489 (.user.ini does not inherit). (cmb)
89

Zend/tests/bug79599.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Bug #79599 (coredump in set_error_handler)
3+
--FILE--
4+
<?php
5+
set_error_handler(function($code, $message){
6+
throw new \Exception($message);
7+
});
8+
function test1(){
9+
$a[] = $b;
10+
}
11+
function test2(){
12+
$a[$c] = $b;
13+
}
14+
try{
15+
test1();
16+
}catch(\Exception $e){
17+
var_dump($e->getMessage());
18+
}
19+
try{
20+
test2();
21+
}catch(\Exception $e){
22+
var_dump($e->getMessage());
23+
}
24+
?>
25+
--EXPECT--
26+
string(21) "Undefined variable: b"
27+
string(21) "Undefined variable: c"

Zend/zend.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,10 @@ ZEND_API zval *zend_get_configuration_directive(zend_string *name) /* {{{ */
12481248
} \
12491249
} while (0)
12501250

1251+
static void arg_copy_ctor(zval *zv) {
1252+
zval_copy_ctor(zv);
1253+
}
1254+
12511255
static ZEND_COLD void zend_error_va_list(
12521256
int type, const char *error_filename, uint32_t error_lineno,
12531257
const char *format, va_list args)
@@ -1341,7 +1345,9 @@ static ZEND_COLD void zend_error_va_list(
13411345
if (!symbol_table) {
13421346
ZVAL_NULL(&params[4]);
13431347
} else {
1344-
ZVAL_ARR(&params[4], zend_array_dup(symbol_table));
1348+
array_init(&params[4]);
1349+
/* always try to do noninvasive duplication */
1350+
zend_hash_copy(Z_ARRVAL(params[4]), symbol_table, arg_copy_ctor);
13451351
}
13461352

13471353
ZVAL_COPY_VALUE(&orig_user_error_handler, &EG(user_error_handler));

0 commit comments

Comments
 (0)