Skip to content

Fix segfault raise by bad from_xml callback #18119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ext/soap/php_packet_soap.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,15 @@ int parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunction
if (tmp != NULL && tmp->children != NULL) {
zval zv;
master_to_zval(&zv, get_conversion(IS_STRING), tmp);
convert_to_string(&zv)
faultstring = Z_STR(zv);
}

tmp = get_node(fault->children, "faultactor");
if (tmp != NULL && tmp->children != NULL) {
zval zv;
master_to_zval(&zv, get_conversion(IS_STRING), tmp);
convert_to_string(&zv)
faultactor = Z_STR(zv);
}

Expand All @@ -222,6 +224,7 @@ int parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunction
if (tmp != NULL && tmp->children != NULL) {
zval zv;
master_to_zval(&zv, get_conversion(IS_STRING), tmp);
convert_to_string(&zv)
faultstring = Z_STR(zv);
}
}
Expand Down
48 changes: 48 additions & 0 deletions ext/soap/tests/bugs/bug66049.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
--TEST--
Fix #66049 Typemap can break parsing in parse_packet_soap leading to a segfault
--EXTENSIONS--
soap
--INI--
soap.wsdl_cache_enabled=0
--FILE--
<?php
function soap_string_from_xml($str)
{
echo "soap_string_from_xml\n";

// Should return an string
return 2.3;
}

class TestSoapClient extends SoapClient {
function __doRequest($request, $location, $action, $version, $one_way = 0): ?string {
$res='<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault><faultcode>SOAP-ENV:Server</faultcode><faultstring>not present</faultstring>
</SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>';
return $res;
}
}

try {
$client=new TestSoapClient(null, [
'uri' => 'test://',
'location' => 'test://',
'typemap' => [[
"type_ns" => "http://www.w3.org/2001/XMLSchema",
"type_name" => "string",
"from_xml" => "soap_string_from_xml"
]]]);
$client->Mist("");
} catch (SoapFault $e) {
var_dump($e->faultstring);
var_dump($e->faultcode);
}
?>
Done
--EXPECT--
soap_string_from_xml
string(3) "2.3"
string(15) "SOAP-ENV:Server"
Done
Loading