Skip to content

ext/soap: fix DTD node being matched as an element - #25605

Closed
bukka wants to merge 1 commit into
php:PHP-8.2from
bukka:soap_dtd_regression
Closed

bukka wants to merge 1 commit into
php:PHP-8.2from
bukka:soap_dtd_regression

Conversation

@bukka

@bukka bukka commented Nov 19, 2026

Copy link
Copy Markdown
Member

The DTD node kept by the GHSA-4646-p932-gw34 fix is named after the DOCTYPE, so lookups for definitions, schema or Envelope could return it.

@ndossche ndossche left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is complete, see Slack

@devnexen devnexen linked an issue Nov 21, 2026 that may be closed by this pull request
3 tasks done

@ndossche ndossche left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following is a more complete fix:

diff --git a/ext/soap/php_encoding.c b/ext/soap/php_encoding.c
index 32ba6c7524f..8fbfc03487d 100644
--- a/ext/soap/php_encoding.c
+++ b/ext/soap/php_encoding.c
@@ -609,8 +609,12 @@ xmlNodePtr to_xml_user(encodeTypePtr type, zval *data, int style, xmlNodePtr par
 		}
 		if (Z_TYPE(return_value) == IS_STRING) {
 			xmlDocPtr doc = soap_xmlParseMemory(Z_STRVAL(return_value), Z_STRLEN(return_value));
-			if (doc && doc->children) {
-				ret = xmlDocCopyNode(doc->children, parent->doc, 1);
+			if (doc) {
+				/* Skip a DOCTYPE or processing instruction before the root. */
+				xmlNodePtr root = xmlDocGetRootElement(doc);
+				if (root) {
+					ret = xmlDocCopyNode(root, parent->doc, 1);
+				}
 			}
 			xmlFreeDoc(doc);
 		}
diff --git a/ext/soap/php_xml.c b/ext/soap/php_xml.c
index a692ba8dcdc..1e4cc4a2377 100644
--- a/ext/soap/php_xml.c
+++ b/ext/soap/php_xml.c
@@ -276,6 +276,10 @@ int attr_is_equal_ex(xmlAttrPtr node, char *name, char *ns)
 
 int node_is_equal_ex(xmlNodePtr node, char *name, char *ns)
 {
+	/* A DTD node can carry the same name but is not an xmlNode. */
+	if (node->type != XML_ELEMENT_NODE) {
+		return FALSE;
+	}
 	if (name == NULL || ((node->name) && strcmp((char*)node->name, name) == 0)) {
 		if (ns) {
 			xmlNsPtr nsPtr = node_find_ns(node);
@@ -339,6 +343,9 @@ xmlNodePtr get_node_with_attribute_ex(xmlNodePtr node, char *name, char *name_ns
 			if (node==NULL) {
 				return NULL;
 			}
+		} else if (node->type != XML_ELEMENT_NODE) {
+			node = node->next;
+			continue;
 		}
 
 		attr = get_attribute_ex(node->properties, attribute, attr_ns);

Also, please double check when merging up that other get_node_* code doesn't need additional changes

The DTD node kept by the GHSA-4646-p932-gw34 fix is named after the
DOCTYPE, so lookups for definitions, schema or Envelope could return it.
Typemap to_xml() output with a DOCTYPE or PI before the root is now
handled as well.

Fixes phpGH-25628

Co-authored-by: ndossche <7771979+ndossche@users.noreply.github.com>
@bukka
bukka force-pushed the soap_dtd_regression branch from 7d78fee to cec014b Compare November 21, 2026 15:46
@bukka bukka closed this in 7d0baa8 Nov 30, 2026
azsupport pushed a commit to azsupport/php-src that referenced this pull request Dec 4, 2026
The DTD node kept by the GHSA-4646-p932-gw34 fix is named after the
DOCTYPE, so lookups for definitions, schema or Envelope could return it.
Typemap to_xml() output with a DOCTYPE or PI before the root is now
handled as well.

Fixes phpGH-25628
Closes phpGH-25605

Co-authored-by: ndossche <7771979+ndossche@users.noreply.github.com>
(cherry picked from commit 7d0baa8)
(cherry picked from commit 8acdc6c)
(cherry picked from commit c74a2c767e8ba60c18822caece51810a111fa0ee)
azsupport pushed a commit to azsupport/php-src that referenced this pull request Dec 4, 2026
The DTD node kept by the GHSA-4646-p932-gw34 fix is named after the
DOCTYPE, so lookups for definitions, schema or Envelope could return it.
Typemap to_xml() output with a DOCTYPE or PI before the root is now
handled as well.

Fixes phpGH-25628
Closes phpGH-25605

Co-authored-by: ndossche <7771979+ndossche@users.noreply.github.com>
(cherry picked from commit 7d0baa8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PHP 8.3.37 SOAP crashes when importing the XMLDSIG schema

2 participants