Skip to content
Closed
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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,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 various memory related issues in ext/sockets. (David Carlier)
Expand Down
2 changes: 1 addition & 1 deletion ext/simplexml/simplexml.c
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,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;
Expand Down
28 changes: 28 additions & 0 deletions ext/simplexml/tests/bug_sxe_compare_uninitialized.phpt
Original file line number Diff line number Diff line change
@@ -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
Loading