mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
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.
This commit is contained in:
parent
734afa0ba8
commit
d7de0ceca6
3 changed files with 31 additions and 0 deletions
3
NEWS
3
NEWS
|
@ -2,6 +2,9 @@ PHP NEWS
|
|||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||
?? ??? ????, PHP 8.1.26
|
||||
|
||||
- DOM:
|
||||
. Fix registerNodeClass with abstract class crashing. (nielsdos)
|
||||
|
||||
- Fiber:
|
||||
. Fixed bug GH-11121 (ReflectionFiber segfault). (danog, trowski, bwoebi)
|
||||
|
||||
|
|
|
@ -2096,6 +2096,10 @@ PHP_METHOD(DOMDocument, registerNodeClass)
|
|||
}
|
||||
|
||||
if (ce == NULL || instanceof_function(ce, basece)) {
|
||||
if (UNEXPECTED(ce != NULL && (ce->ce_flags & ZEND_ACC_ABSTRACT))) {
|
||||
zend_argument_value_error(2, "must not be an abstract class");
|
||||
RETURN_THROWS();
|
||||
}
|
||||
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
|
||||
dom_set_doc_classmap(intern->document, basece, ce);
|
||||
RETURN_TRUE;
|
||||
|
|
24
ext/dom/tests/registerNodeClass_abstract_class.phpt
Normal file
24
ext/dom/tests/registerNodeClass_abstract_class.phpt
Normal file
|
@ -0,0 +1,24 @@
|
|||
--TEST--
|
||||
registerNodeClass() with an abstract class should fail
|
||||
--EXTENSIONS--
|
||||
dom
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
abstract class Test extends DOMElement {
|
||||
abstract function foo();
|
||||
}
|
||||
|
||||
$dom = new DOMDocument;
|
||||
|
||||
try {
|
||||
$dom->registerNodeClass("DOMElement", "Test");
|
||||
} catch (ValueError $e) {
|
||||
echo "ValueError: ", $e->getMessage(), "\n";
|
||||
}
|
||||
|
||||
$dom->createElement("foo");
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
ValueError: DOMDocument::registerNodeClass(): Argument #2 ($extendedClass) must not be an abstract class
|
Loading…
Add table
Add a link
Reference in a new issue