diff --git a/ext/soap/php_encoding.c b/ext/soap/php_encoding.c index 8d869b6705dd..05e12de5f021 100644 --- 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 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); diff --git a/ext/soap/tests/gh25303.phpt b/ext/soap/tests/gh25303.phpt new file mode 100644 index 000000000000..d58c36d4efdc --- /dev/null +++ b/ext/soap/tests/gh25303.phpt @@ -0,0 +1,36 @@ +--TEST-- +GH-25303 (NULL encode dereference in to_xml_list() error path for union types) +--EXTENSIONS-- +soap +--CREDITS-- +YuanchengJiang +--FILE-- + + + + + + + + + + + + + + + + +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'