Skip to content

Commit 63e1ebe

Browse files
committed
Fix GH-16149: Null pointer dereference in DOMElement->getAttributeNames()
A namespace without a prefix is by definition always the "xmlns" namespace. Closes GH-16155.
1 parent 4a16940 commit 63e1ebe

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ PHP NEWS
1414
- DOM:
1515
. Fixed bug GH-16039 (Segmentation fault (access null pointer) in
1616
ext/dom/parentnode/tree.c). (nielsdos)
17+
. Fixed bug GH-16149 (Null pointer dereference in
18+
DOMElement->getAttributeNames()). (nielsdos)
1719

1820
- JSON:
1921
. Fixed bug GH-15168 (stack overflow in json_encode()). (nielsdos)

ext/dom/element.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,11 @@ PHP_METHOD(DOMElement, getAttributeNames)
339339

340340
for (xmlNsPtr nsptr = nodep->nsDef; nsptr; nsptr = nsptr->next) {
341341
const char *prefix = (const char *) nsptr->prefix;
342-
ZVAL_STR(&tmp, dom_node_concatenated_name_helper(strlen(prefix), prefix, strlen("xmlns"), (const char *) "xmlns"));
342+
if (prefix == NULL) {
343+
ZVAL_STRING(&tmp, "xmlns");
344+
} else {
345+
ZVAL_STR(&tmp, dom_node_concatenated_name_helper(strlen(prefix), prefix, strlen("xmlns"), (const char *) "xmlns"));
346+
}
343347
zend_hash_next_index_insert(ht, &tmp);
344348
}
345349

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)