Skip to content

Commit 9d7e609

Browse files
authored
Fix GH-15137: Unexpected null pointer in Zend/zend_smart_str.h (#15138)
This regressed when I optimized $wholeText. The previous code used xmlStrcat which implicitly checked for a NULL argument, but now it's a direct memcpy which you shouldn't pass null pointers to, although it won't result in a crash because memcpy doesn't do anything if the length is 0.
1 parent dee2944 commit 9d7e609

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

ext/dom/tests/gh15137.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
GH-15137: Unexpected null pointer in Zend/zend_smart_str.h
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
var_dump(new DOMText()->wholeText);
8+
?>
9+
--EXPECT--
10+
string(0) ""
11+

ext/dom/text.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ zend_result dom_text_whole_text_read(dom_object *obj, zval *retval)
7777

7878
/* concatenate all adjacent text and cdata nodes */
7979
while (node && ((node->type == XML_TEXT_NODE) || (node->type == XML_CDATA_SECTION_NODE))) {
80-
smart_str_appends(&str, (const char *) node->content);
80+
if (node->content) {
81+
smart_str_appends(&str, (const char *) node->content);
82+
}
8183
node = node->next;
8284
}
8385

0 commit comments

Comments
 (0)