Skip to content

Commit eb8c3cb

Browse files
committed
Fix GH-14741: Segmentation fault in Zend/zend_types.h
The create_obj handler of InternalIterator is overwritten, but not the clone_obj handler. This is not allowed. In PHP 8.2 this didn't cause a segfault because the standard object handler was used for the clone instead of the internal handler. So then it allocates and frees the object using the standard object handlers. In 8.3 however, the object is created using the standard object handler and freed using the custom handler, resulting in the buffer overflow. Even though bisect points to 1e1ea4f this only reveals the bug. Closes GH-14882.
1 parent 43e3f57 commit eb8c3cb

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ PHP NEWS
99
. Fixed bug GH-14590 (Memory leak in FPM test gh13563-conf-bool-env.phpt.
1010
(nielsdos)
1111
. Fixed OSS-Fuzz #69765. (nielsdos)
12+
. Fixed bug GH-14741 (Segmentation fault in Zend/zend_types.h). (nielsdos)
1213

1314
- Dom:
1415
. Fixed bug GH-14702 (DOMDocument::xinclude() crash). (nielsdos)

Zend/zend_interfaces.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@ ZEND_API void zend_register_interfaces(void)
666666

667667
memcpy(&zend_internal_iterator_handlers, zend_get_std_object_handlers(),
668668
sizeof(zend_object_handlers));
669+
zend_internal_iterator_handlers.clone_obj = NULL;
669670
zend_internal_iterator_handlers.free_obj = zend_internal_iterator_free;
670671
}
671672
/* }}} */

ext/zend_test/tests/gh14741.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
GH-14741 (Segmentation fault in Zend/zend_types.h)
3+
--EXTENSIONS--
4+
zend_test
5+
--FILE--
6+
<?php
7+
$subject = new \ZendTest\Iterators\TraversableTest();
8+
$it = $subject->getIterator();
9+
try {
10+
clone $it;
11+
} catch (Error $e) {
12+
echo $e->getMessage(), "\n";
13+
}
14+
?>
15+
--EXPECT--
16+
Trying to clone an uncloneable object of class InternalIterator
17+
TraversableTest::drop

0 commit comments

Comments
 (0)