Skip to content

Commit 05703d7

Browse files
committed
Fixed bug #36303 (foreach on error_zval produces segfault)
1 parent 6195ce8 commit 05703d7

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ PHP NEWS
44
- Fixed an error in mysqli_fetch_fields (returned NULL instead of an
55
array when row number > field_count). (Georg)
66
- Renamed CachingRecursiveIterator to RecursiveCachingIterator. (Marcus)
7+
- Fixed bug #36303 (foreach on error_zval produces segfault). (Dmitry)
78
- Fixed bug #36071 (Engine Crash related with 'clone'). (Dmitry)
89
- Fixed bug #36006 (Problem with $this in __destruct()). (Dmitry)
910
- Fixed bug #35612 (iis6 Access Violation crash). (Dmitry, alacn.uhahaa)

Zend/tests/bug36303.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Bug #36303 (foreach on error_zval produces segfault)
3+
--FILE--
4+
<?php
5+
$x="test";
6+
foreach($x->a->b as &$v) {
7+
}
8+
echo "ok\n";
9+
?>
10+
--EXPECTF--
11+
Warning: Invalid argument supplied for foreach() in %sbug36303.php on line 3
12+
ok

Zend/zend_execute.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3815,7 +3815,9 @@ int zend_fe_reset_handler(ZEND_OPCODE_HANDLER_ARGS)
38153815
}
38163816
array_ptr = *array_ptr_ptr;
38173817
} else {
3818-
SEPARATE_ZVAL_IF_NOT_REF(array_ptr_ptr);
3818+
if (Z_TYPE_PP(array_ptr_ptr) == IS_ARRAY) {
3819+
SEPARATE_ZVAL_IF_NOT_REF(array_ptr_ptr);
3820+
}
38193821
array_ptr = *array_ptr_ptr;
38203822
array_ptr->refcount++;
38213823
}

0 commit comments

Comments
 (0)