From a9b656b1e68ce0e7fa6c1e1acf7cc419ad1712dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Fri, 23 Apr 2021 18:40:54 +0200 Subject: [PATCH 1/3] Fix arginfo/ZPP mismatch for simplexml_import_dom --- ext/simplexml/simplexml.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index c941e43ad37b9..8793af798d9b2 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -2619,8 +2619,6 @@ PHP_FUNCTION(simplexml_import_dom) RETURN_THROWS(); } - object = Z_LIBXML_NODE_P(node); - nodep = php_libxml_import_node(node); if (nodep) { @@ -2631,15 +2629,21 @@ PHP_FUNCTION(simplexml_import_dom) if (nodep->type == XML_DOCUMENT_NODE || nodep->type == XML_HTML_DOCUMENT_NODE) { nodep = xmlDocGetRootElement((xmlDocPtr) nodep); } + } else { + zend_argument_type_error(1, "must be of type DOMNode, %s given", zend_zval_type_name(node)); + RETURN_THROWS(); } - if (nodep && nodep->type == XML_ELEMENT_NODE) { + if (nodep->type == XML_ELEMENT_NODE) { if (!ce) { ce = sxe_class_entry; fptr_count = NULL; } else { fptr_count = php_sxe_find_fptr_count(ce); } + + object = Z_LIBXML_NODE_P(node); + sxe = php_sxe_object_new(ce, fptr_count); sxe->document = object->document; php_libxml_increment_doc_ref((php_libxml_node_object *)sxe, nodep->doc); From 43c3d78007047c7c795de9559939a11f12e65ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Fri, 23 Apr 2021 22:01:39 +0200 Subject: [PATCH 2/3] Use early return --- ext/simplexml/simplexml.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 8793af798d9b2..76d76fd6974ad 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -2621,19 +2621,20 @@ PHP_FUNCTION(simplexml_import_dom) nodep = php_libxml_import_node(node); - if (nodep) { - if (nodep->doc == NULL) { - php_error_docref(NULL, E_WARNING, "Imported Node must have associated Document"); - RETURN_NULL(); - } - if (nodep->type == XML_DOCUMENT_NODE || nodep->type == XML_HTML_DOCUMENT_NODE) { - nodep = xmlDocGetRootElement((xmlDocPtr) nodep); - } - } else { + if (!nodep) { zend_argument_type_error(1, "must be of type DOMNode, %s given", zend_zval_type_name(node)); RETURN_THROWS(); } + if (nodep->doc == NULL) { + php_error_docref(NULL, E_WARNING, "Imported Node must have associated Document"); + RETURN_NULL(); + } + + if (nodep->type == XML_DOCUMENT_NODE || nodep->type == XML_HTML_DOCUMENT_NODE) { + nodep = xmlDocGetRootElement((xmlDocPtr) nodep); + } + if (nodep->type == XML_ELEMENT_NODE) { if (!ce) { ce = sxe_class_entry; From 4ef341d1735c1d332a0451aac28832f43fa50cfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Fri, 23 Apr 2021 22:23:55 +0200 Subject: [PATCH 3/3] Fix parameter type --- ext/simplexml/simplexml.c | 2 +- ext/simplexml/simplexml.stub.php | 2 +- ext/simplexml/simplexml_arginfo.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 76d76fd6974ad..4ed41d7587626 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -2622,7 +2622,7 @@ PHP_FUNCTION(simplexml_import_dom) nodep = php_libxml_import_node(node); if (!nodep) { - zend_argument_type_error(1, "must be of type DOMNode, %s given", zend_zval_type_name(node)); + zend_argument_type_error(1, "must be of type SimpleXMLElement|DOMNode, %s given", zend_zval_type_name(node)); RETURN_THROWS(); } diff --git a/ext/simplexml/simplexml.stub.php b/ext/simplexml/simplexml.stub.php index 7d56de88e9fec..0363c62d3fdca 100644 --- a/ext/simplexml/simplexml.stub.php +++ b/ext/simplexml/simplexml.stub.php @@ -6,7 +6,7 @@ function simplexml_load_file(string $filename, ?string $class_name = SimpleXMLEl function simplexml_load_string(string $data, ?string $class_name = SimpleXMLElement::class, int $options = 0, string $namespace_or_prefix = "", bool $is_prefix = false): SimpleXMLElement|false {} -function simplexml_import_dom(DOMNode $node, ?string $class_name = SimpleXMLElement::class): ?SimpleXMLElement {} +function simplexml_import_dom(SimpleXMLElement|DOMNode $node, ?string $class_name = SimpleXMLElement::class): ?SimpleXMLElement {} class SimpleXMLElement implements Stringable, Countable, RecursiveIterator { diff --git a/ext/simplexml/simplexml_arginfo.h b/ext/simplexml/simplexml_arginfo.h index 7da3c9f33c608..72f1dc9a32a8c 100644 --- a/ext/simplexml/simplexml_arginfo.h +++ b/ext/simplexml/simplexml_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: f8ca25a00ae1a5fed436851e88229b503c77bf31 */ + * Stub hash: 70ace711365bb5e7df3174d4cfe68fb3df34a105 */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_simplexml_load_file, 0, 1, SimpleXMLElement, MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) @@ -18,7 +18,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_simplexml_load_string, 0, 1, ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_simplexml_import_dom, 0, 1, SimpleXMLElement, 1) - ZEND_ARG_OBJ_INFO(0, node, DOMNode, 0) + ZEND_ARG_OBJ_TYPE_MASK(0, node, SimpleXMLElement|DOMNode, 0, NULL) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, class_name, IS_STRING, 1, "SimpleXMLElement::class") ZEND_END_ARG_INFO()