Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ PHP NEWS
. Fixed bug GH-23043 (broken session id code can cause zend_mm_heap
corrupted). (ndossche)

- SimpleXML:
. Fixed segfault when comparing uninitialized SimpleXMLElement
instances. (iliaal)

- Sockets:
. Fixed various memory related issues in ext/sockets. (David Carlier)

Expand Down
6 changes: 6 additions & 0 deletions ext/simplexml/simplexml.c
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,12 @@ 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 == NULL || sxe2->document == NULL) {
if (sxe1->document == sxe2->document) {
return 0;
}
return ZEND_UNCOMPARABLE;
}
if (sxe1->document->ptr == sxe2->document->ptr) {
return 0;
}
Expand Down
25 changes: 25 additions & 0 deletions ext/simplexml/tests/bug_sxe_compare_uninitialized.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--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 "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--
equal: bool(true)
identical: bool(false)
uninit vs init: bool(false)
done
Loading