Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions ext/soap/php_encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -3080,6 +3080,17 @@ static zval* to_zval_list(zval *ret, encodeTypePtr enc, xmlNodePtr data) {
return to_zval_stringc(ret, enc, data);
}

static void to_xml_list_item_error(encodeTypePtr enc, encodePtr list_enc)
{
if (enc->sdl_type && enc->sdl_type->kind == XSD_TYPEKIND_UNION) {
soap_error1(E_ERROR, "Encoding: Value does not match any member type of union type '%s'",
soap_type_name(enc));
} else {
soap_error2(E_ERROR, "Encoding: Failed to encode list item of type '%s' for list type '%s'",
soap_type_name(list_enc ? &list_enc->details : NULL), soap_type_name(enc));
}
}

static xmlNodePtr to_xml_list(encodeTypePtr enc, zval *data, int style, xmlNodePtr parent) {
xmlNodePtr ret;
encodePtr list_enc = NULL;
Expand Down Expand Up @@ -3115,9 +3126,7 @@ static xmlNodePtr to_xml_list(encodeTypePtr enc, zval *data, int style, xmlNodeP
}
smart_str_appends(&list, (char*)dummy->children->content);
} else {

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.

--- a/ext/soap/php_encoding.c
+++ b/ext/soap/php_encoding.c
@@ -3080,6 +3080,17 @@ static zval* to_zval_list(zval *ret, encodeTypePtr enc, xmlNodePtr data) {
        return to_zval_stringc(ret, enc, data);
 }

+static void to_xml_list_item_error(encodeTypePtr enc, encodePtr list_enc)
+{
+       if (enc->sdl_type && enc->sdl_type->kind == XSD_TYPEKIND_UNION) {
+               soap_error1(E_ERROR, "Encoding: Value does not match any member type of union type '%s'",
+                       soap_type_name(enc));
+       } else {
+               soap_error2(E_ERROR, "Encoding: Failed to encode list item of type '%s' for list type '%s'",
+                       soap_type_name(list_enc ? &list_enc->details : NULL), soap_type_name(enc));
+       }
+}
+
 static xmlNodePtr to_xml_list(encodeTypePtr enc, zval *data, int style, xmlNodePtr parent) {
        xmlNodePtr ret;
        encodePtr list_enc = NULL;
@@ -3115,9 +3126,7 @@ static xmlNodePtr to_xml_list(encodeTypePtr enc, zval *data, int style, xmlNodeP
                                }
                                smart_str_appends(&list, (char*)dummy->children->content);
                        } else {
-                               soap_error2(E_ERROR,
-                                       "Encoding: Failed to encode list item of type '%s' for list type '%s'",
-                                       soap_type_name(&list_enc->details), soap_type_name(enc));
+                               to_xml_list_item_error(enc, list_enc);
                        }
                        xmlUnlinkNode(dummy);
                        xmlFreeNode(dummy);
@@ -3159,9 +3168,7 @@ static xmlNodePtr to_xml_list(encodeTypePtr enc, zval *data, int style, xmlNodeP
                                }
                                smart_str_appends(&list, (char*)dummy->children->content);
                        } else {
-                               soap_error2(E_ERROR,
-                                       "Encoding: Failed to encode st type '%s'",
-                                       soap_type_name(&list_enc->details), soap_type_name(enc));
+                               to_xml_list_item_error(enc, list_enc
                        }
                        xmlUnlinkNode(dummy);
                        xmlFreeNode(dummy);

soap_error2(E_ERROR,
"Encoding: Failed to encode list item of type '%s' for list type '%s'",
soap_type_name(&list_enc->details), soap_type_name(enc));
to_xml_list_item_error(enc, list_enc);
}
xmlUnlinkNode(dummy);
xmlFreeNode(dummy);
Expand Down Expand Up @@ -3159,9 +3168,7 @@ static xmlNodePtr to_xml_list(encodeTypePtr enc, zval *data, int style, xmlNodeP
}
smart_str_appends(&list, (char*)dummy->children->content);
} else {
soap_error2(E_ERROR,
"Encoding: Failed to encode list item of type '%s' for list type '%s'",
soap_type_name(&list_enc->details), soap_type_name(enc));
to_xml_list_item_error(enc, list_enc);
}
xmlUnlinkNode(dummy);
xmlFreeNode(dummy);
Expand Down
36 changes: 36 additions & 0 deletions ext/soap/tests/gh25303.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--TEST--
GH-25303 (NULL encode dereference in to_xml_list() error path for union types)
--EXTENSIONS--
soap
--CREDITS--
YuanchengJiang
--FILE--
<?php
$wsdl = <<<XML
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="urn:t" targetNamespace="urn:t">
<types>
<xsd:schema targetNamespace="urn:t">
<xsd:simpleType name="U"><xsd:union memberTypes="xsd:int"/></xsd:simpleType>
</xsd:schema>
</types>
<message name="m"><part name="p" type="tns:U"/></message>
<portType name="pt"><operation name="test"><input message="tns:m"/></operation></portType>
<binding name="b" type="tns:pt">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="test"><soap:operation soapAction="#test"/>
<input><soap:body use="encoded" namespace="urn:t" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>
</operation>
</binding>
<service name="s"><port name="p" binding="tns:b"><soap:address location="test://"/></port></service>
</definitions>
XML;
$c = new SoapClient("data://text/plain;base64," . base64_encode($wsdl), ["cache_wsdl" => WSDL_CACHE_NONE]);
try {
$c->test([[1]]);
} catch (SoapFault $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
SOAP-ERROR: Encoding: Value does not match any member type of union type 'U'
Loading