Skip to content

Commit d7de0ce

Browse files
committed
Fix registerNodeClass with abstract class crashing
This always results in a segfault when trying to instantiate, so this never worked. At least throw an error instead of segfaulting to prevent developers from being confused. Closes GH-12420.
1 parent 734afa0 commit d7de0ce

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.1.26
44

5+
- DOM:
6+
. Fix registerNodeClass with abstract class crashing. (nielsdos)
7+
58
- Fiber:
69
. Fixed bug GH-11121 (ReflectionFiber segfault). (danog, trowski, bwoebi)
710

ext/dom/document.c

+4
Original file line numberDiff line numberDiff line change
@@ -2096,6 +2096,10 @@ PHP_METHOD(DOMDocument, registerNodeClass)
20962096
}
20972097

20982098
if (ce == NULL || instanceof_function(ce, basece)) {
2099+
if (UNEXPECTED(ce != NULL && (ce->ce_flags & ZEND_ACC_ABSTRACT))) {
2100+
zend_argument_value_error(2, "must not be an abstract class");
2101+
RETURN_THROWS();
2102+
}
20992103
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
21002104
dom_set_doc_classmap(intern->document, basece, ce);
21012105
RETURN_TRUE;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
registerNodeClass() with an abstract class should fail
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
abstract class Test extends DOMElement {
9+
abstract function foo();
10+
}
11+
12+
$dom = new DOMDocument;
13+
14+
try {
15+
$dom->registerNodeClass("DOMElement", "Test");
16+
} catch (ValueError $e) {
17+
echo "ValueError: ", $e->getMessage(), "\n";
18+
}
19+
20+
$dom->createElement("foo");
21+
22+
?>
23+
--EXPECT--
24+
ValueError: DOMDocument::registerNodeClass(): Argument #2 ($extendedClass) must not be an abstract class

0 commit comments

Comments
 (0)