[php-src] PHP-8.5: Merge branch 'PHP-8.4' into PHP-8.5
Ilia Alshanetsky <[email protected]>
| Newsgroups | gmane.comp.php.cvs.general |
|---|---|
| Message-ID | <[email protected]> |
Author: Ilia Alshanetsky (iliaal)
Date: 2026-08-10T10:23:26-04:00
Commit: https://github.com/php/php-src/commit/2806a3637e6025ea532276742cb5c1b95882df5c
Raw diff: https://github.com/php/php-src/commit/2806a3637e6025ea532276742cb5c1b95882df5c.diff
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
Fix segfault comparing uninitialized SimpleXMLElement instances
Changed paths:
A ext/simplexml/tests/bug_sxe_compare_uninitialized.phpt
M NEWS
M ext/simplexml/simplexml.c
Diff:
diff --git a/NEWS b/NEWS
index 104d19a7744e..ade754593071 100644
--- a/NEWS
+++ b/NEWS
@@ -67,6 +67,8 @@ PHP NEWS
- SimpleXML:
. Fixed integer element offsets that cannot resolve aliasing an existing
element. (iliaal)
+ . Fixed segfault when comparing uninitialized SimpleXMLElement
+ instances. (iliaal)
- Sockets:
. Fixed socket_set_option() validation error messages for UDP_SEGMENT and
diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c
index e537bc3fb20e..b51ee3509b75 100644
--- a/ext/simplexml/simplexml.c
+++ b/ext/simplexml/simplexml.c
@@ -1214,7 +1214,7 @@ static int sxe_objects_compare(zval *object1, zval *object2) /* {{{ */
if (sxe1->node == NULL && sxe2->node == NULL) {
/* Both nodes not set: Only support equality comparison between documents. */
- if (sxe1->document->ptr == sxe2->document->ptr) {
+ if (sxe1->document != NULL && sxe2->document != NULL && sxe1->document->ptr == sxe2->document->ptr) {
return 0;
}
return ZEND_UNCOMPARABLE;
diff --git a/ext/simplexml/tests/bug_sxe_compare_uninitialized.phpt b/ext/simplexml/tests/bug_sxe_compare_uninitialized.phpt
new file mode 100644
index 000000000000..4d915b66c3a3
--- /dev/null
+++ b/ext/simplexml/tests/bug_sxe_compare_uninitialized.phpt
@@ -0,0 +1,28 @@
+--TEST--
+Comparing uninitialized SimpleXMLElement instances must not segfault
+--EXTENSIONS--
+simplexml
+--FILE--
+<?php
+class MySXE extends SimpleXMLElement {
+ public function __construct() {}
+}
+$a = new MySXE;
+$b = new MySXE;
+echo "self: ";
+var_dump($a == $a);
+echo "equal: ";
+var_dump($a == $b);
+echo "identical: ";
+var_dump($a === $b);
+$c = simplexml_load_string('<r/>');
+echo "uninit vs init: ";
+var_dump($a == $c);
+echo "done\n";
+?>
+--EXPECT--
+self: bool(true)
+equal: bool(false)
+identical: bool(false)
+uninit vs init: bool(false)
+done