Skip to content

Commit 70b2fda

Browse files
committed
Handle value being unset during dep
1 parent 6b669f4 commit 70b2fda

File tree

3 files changed

+316
-0
lines changed

3 files changed

+316
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
No UAF on null offset deprecation with unset value
3+
--FILE--
4+
<?php
5+
set_error_handler(function ($errno, $errstr) {
6+
var_dump($errstr);
7+
global $a;
8+
unset($a);
9+
});
10+
11+
$a = new stdClass;
12+
$b = [0, null => $a];
13+
14+
echo "\nSuccess\n";
15+
?>
16+
--EXPECTF--
17+
string(72) "Using null as an array offset is deprecated, use an empty string instead"
18+
19+
Success

Zend/zend_vm_def.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6279,7 +6279,16 @@ ZEND_VM_C_LABEL(num_index):
62796279
offset = Z_REFVAL_P(offset);
62806280
ZEND_VM_C_GOTO(add_again);
62816281
} else if (UNEXPECTED(Z_TYPE_P(offset) == IS_NULL)) {
6282+
zval tmp;
6283+
if (OP1_TYPE == IS_CV || OP1_TYPE == IS_VAR) {
6284+
ZVAL_COPY(&tmp, expr_ptr);
6285+
}
62826286
zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead");
6287+
if (OP1_TYPE == IS_CV || OP1_TYPE == IS_VAR) {
6288+
/* A userland error handler can do funky things to the expression, so reset it */
6289+
zval_ptr_dtor(expr_ptr);
6290+
ZVAL_COPY_VALUE(expr_ptr, &tmp);
6291+
}
62836292
if (UNEXPECTED(EG(exception))) {
62846293
zval_ptr_dtor_nogc(expr_ptr);
62856294
HANDLE_EXCEPTION();

0 commit comments

Comments
 (0)