Skip to content

Commit efd8d99

Browse files
committed
Merge branch 'PHP-8.6'
* PHP-8.6: Fix GH-25303: NULL encoder dereference in to_xml_list() error message
2 parents d1ec606 + 18ece89 commit efd8d99

2 files changed

Lines changed: 49 additions & 6 deletions

File tree

‎ext/soap/php_encoding.c‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3076,6 +3076,17 @@ static zval* to_zval_list(zval *ret, encodeTypePtr enc, xmlNodePtr data) {
30763076
return to_zval_stringc(ret, enc, data);
30773077
}
30783078

3079+
static void to_xml_list_item_error(encodeTypePtr enc, encodePtr list_enc)
3080+
{
3081+
if (enc->sdl_type && enc->sdl_type->kind == XSD_TYPEKIND_UNION) {
3082+
soap_error1(E_ERROR, "Encoding: Value does not match any member type of union type '%s'",
3083+
soap_type_name(enc));
3084+
} else {
3085+
soap_error2(E_ERROR, "Encoding: Failed to encode list item of type '%s' for list type '%s'",
3086+
soap_type_name(list_enc ? &list_enc->details : NULL), soap_type_name(enc));
3087+
}
3088+
}
3089+
30793090
static xmlNodePtr to_xml_list(encodeTypePtr enc, zval *data, int style, xmlNodePtr parent) {
30803091
xmlNodePtr ret;
30813092
encodePtr list_enc = NULL;
@@ -3111,9 +3122,7 @@ static xmlNodePtr to_xml_list(encodeTypePtr enc, zval *data, int style, xmlNodeP
31113122
}
31123123
smart_str_appends(&list, (char*)dummy->children->content);
31133124
} else {
3114-
soap_error2(E_ERROR,
3115-
"Encoding: Failed to encode list item of type '%s' for list type '%s'",
3116-
soap_type_name(&list_enc->details), soap_type_name(enc));
3125+
to_xml_list_item_error(enc, list_enc);
31173126
}
31183127
xmlUnlinkNode(dummy);
31193128
xmlFreeNode(dummy);
@@ -3155,9 +3164,7 @@ static xmlNodePtr to_xml_list(encodeTypePtr enc, zval *data, int style, xmlNodeP
31553164
}
31563165
smart_str_appends(&list, (char*)dummy->children->content);
31573166
} else {
3158-
soap_error2(E_ERROR,
3159-
"Encoding: Failed to encode list item of type '%s' for list type '%s'",
3160-
soap_type_name(&list_enc->details), soap_type_name(enc));
3167+
to_xml_list_item_error(enc, list_enc);
31613168
}
31623169
xmlUnlinkNode(dummy);
31633170
xmlFreeNode(dummy);

‎ext/soap/tests/gh25303.phpt‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
GH-25303 (NULL encode dereference in to_xml_list() error path for union types)
3+
--EXTENSIONS--
4+
soap
5+
--CREDITS--
6+
YuanchengJiang
7+
--FILE--
8+
<?php
9+
$wsdl = <<<XML
10+
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
11+
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="urn:t" targetNamespace="urn:t">
12+
<types>
13+
<xsd:schema targetNamespace="urn:t">
14+
<xsd:simpleType name="U"><xsd:union memberTypes="xsd:int"/></xsd:simpleType>
15+
</xsd:schema>
16+
</types>
17+
<message name="m"><part name="p" type="tns:U"/></message>
18+
<portType name="pt"><operation name="test"><input message="tns:m"/></operation></portType>
19+
<binding name="b" type="tns:pt">
20+
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
21+
<operation name="test"><soap:operation soapAction="#test"/>
22+
<input><soap:body use="encoded" namespace="urn:t" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>
23+
</operation>
24+
</binding>
25+
<service name="s"><port name="p" binding="tns:b"><soap:address location="test://"/></port></service>
26+
</definitions>
27+
XML;
28+
$c = new SoapClient("data://text/plain;base64," . base64_encode($wsdl), ["cache_wsdl" => WSDL_CACHE_NONE]);
29+
try {
30+
$c->test([[1]]);
31+
} catch (SoapFault $e) {
32+
echo $e->getMessage(), "\n";
33+
}
34+
?>
35+
--EXPECT--
36+
SOAP-ERROR: Encoding: Value does not match any member type of union type 'U'

0 commit comments

Comments
 (0)