Skip to content

Fix GH-16259: Soap segfault when classmap instantiation fails #16273

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
wants to merge 1 commit into from
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
20 changes: 15 additions & 5 deletions ext/soap/php_encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,9 @@ static zval *to_zval_object_ex(zval *ret, encodeTypePtr type, xmlNodePtr data, z
return ret;
}

object_init_ex(ret, ce);
if (object_init_ex(ret, ce) != SUCCESS) {
return ret;
}
master_to_zval_int(&base, enc, data);
set_zval_property(ret, "_", &base);
} else {
Expand All @@ -1417,7 +1419,9 @@ static zval *to_zval_object_ex(zval *ret, encodeTypePtr type, xmlNodePtr data, z
if (soap_check_xml_ref(ret, data)) {
return ret;
}
object_init_ex(ret, ce);
if (object_init_ex(ret, ce) != SUCCESS) {
return ret;
}
soap_add_xml_ref(ret, data);
}
} else if (sdlType->kind == XSD_TYPEKIND_EXTENSION &&
Expand Down Expand Up @@ -1462,7 +1466,9 @@ static zval *to_zval_object_ex(zval *ret, encodeTypePtr type, xmlNodePtr data, z
return ret;
}

object_init_ex(ret, ce);
if (object_init_ex(ret, ce) != SUCCESS) {
return ret;
}
soap_add_xml_ref(ret, data);
master_to_zval_int(&base, sdlType->encode, data);
set_zval_property(ret, "_", &base);
Expand All @@ -1473,7 +1479,9 @@ static zval *to_zval_object_ex(zval *ret, encodeTypePtr type, xmlNodePtr data, z
if (soap_check_xml_ref(ret, data)) {
return ret;
}
object_init_ex(ret, ce);
if (object_init_ex(ret, ce) != SUCCESS) {
return ret;
}
soap_add_xml_ref(ret, data);
}
if (sdlType->model) {
Expand Down Expand Up @@ -1533,7 +1541,9 @@ static zval *to_zval_object_ex(zval *ret, encodeTypePtr type, xmlNodePtr data, z
return ret;
}

object_init_ex(ret, ce);
if (object_init_ex(ret, ce) != SUCCESS) {
return ret;
}
soap_add_xml_ref(ret, data);
trav = data->children;

Expand Down
23 changes: 23 additions & 0 deletions ext/soap/tests/bugs/gh16259.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
GH-16259 (Soap segfault when classmap instantiation fails)
--EXTENSIONS--
soap
--FILE--
<?php
abstract class CT_A1 {
}
class CT_A2 extends CT_A1 {
}

$classMap = array("A1" => "CT_A1", "A2" => "CT_A2");
$client = new SoapClient(__DIR__."/bug36575.wsdl", array("trace" => 1, "exceptions" => 0));
$a2 = new CT_A2();
$client->test($a2);
$soapRequest = $client->__getLastRequest();

$server = new SoapServer(__DIR__."/bug36575.wsdl", array("classmap" => $classMap));
$server->handle($soapRequest);
?>
--EXPECT--
<?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>Cannot instantiate abstract class CT_A1</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
Loading