Skip to content

Commit 921a1e3

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix GH-16149: Null pointer dereference in DOMElement->getAttributeNames()
2 parents e8e4d36 + 853322f commit 921a1e3

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

ext/dom/element.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,11 @@ PHP_METHOD(DOMElement, getAttributeNames)
361361
if (!php_dom_follow_spec_intern(intern)) {
362362
for (xmlNsPtr nsptr = nodep->nsDef; nsptr; nsptr = nsptr->next) {
363363
const char *prefix = (const char *) nsptr->prefix;
364-
ZVAL_NEW_STR(&tmp, dom_node_concatenated_name_helper(strlen(prefix), prefix, strlen("xmlns"), (const char *) "xmlns"));
364+
if (prefix == NULL) {
365+
ZVAL_STRING(&tmp, "xmlns");
366+
} else {
367+
ZVAL_NEW_STR(&tmp, dom_node_concatenated_name_helper(strlen(prefix), prefix, strlen("xmlns"), (const char *) "xmlns"));
368+
}
365369
zend_hash_next_index_insert(ht, &tmp);
366370
}
367371
}

ext/dom/tests/gh16149.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
GH-16149 (Null pointer dereference in DOMElement->getAttributeNames())
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
$element = new DOMElement("b", null, "a");
8+
var_dump($element->getAttributeNames());
9+
?>
10+
--EXPECT--
11+
array(1) {
12+
[0]=>
13+
string(5) "xmlns"
14+
}

0 commit comments

Comments
 (0)