Skip to content

Commit 71222f7

Browse files
committed
Fix GH-16259: Soap segfault when classmap instantiation fails
Instantiation failure checks were missing. Closes GH-16273.
1 parent e715dd0 commit 71222f7

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ PHP NEWS
9191
. Fix Soap leaking http_msg on error. (nielsdos)
9292
. Fixed bug GH-16256 (Assertion failure in ext/soap/php_encoding.c:460).
9393
(nielsdos)
94+
. Fixed bug GH-16259 (Soap segfault when classmap instantiation fails).
95+
(nielsdos)
9496

9597
- Standard:
9698
. Fixed bug GH-15613 (overflow on unpack call hex string repeater).

ext/soap/php_encoding.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,9 @@ static zval *to_zval_object_ex(zval *ret, encodeTypePtr type, xmlNodePtr data, z
14081408
return ret;
14091409
}
14101410

1411-
object_init_ex(ret, ce);
1411+
if (object_init_ex(ret, ce) != SUCCESS) {
1412+
return ret;
1413+
}
14121414
master_to_zval_int(&base, enc, data);
14131415
set_zval_property(ret, "_", &base);
14141416
} else {
@@ -1417,7 +1419,9 @@ static zval *to_zval_object_ex(zval *ret, encodeTypePtr type, xmlNodePtr data, z
14171419
if (soap_check_xml_ref(ret, data)) {
14181420
return ret;
14191421
}
1420-
object_init_ex(ret, ce);
1422+
if (object_init_ex(ret, ce) != SUCCESS) {
1423+
return ret;
1424+
}
14211425
soap_add_xml_ref(ret, data);
14221426
}
14231427
} else if (sdlType->kind == XSD_TYPEKIND_EXTENSION &&
@@ -1462,7 +1466,9 @@ static zval *to_zval_object_ex(zval *ret, encodeTypePtr type, xmlNodePtr data, z
14621466
return ret;
14631467
}
14641468

1465-
object_init_ex(ret, ce);
1469+
if (object_init_ex(ret, ce) != SUCCESS) {
1470+
return ret;
1471+
}
14661472
soap_add_xml_ref(ret, data);
14671473
master_to_zval_int(&base, sdlType->encode, data);
14681474
set_zval_property(ret, "_", &base);
@@ -1473,7 +1479,9 @@ static zval *to_zval_object_ex(zval *ret, encodeTypePtr type, xmlNodePtr data, z
14731479
if (soap_check_xml_ref(ret, data)) {
14741480
return ret;
14751481
}
1476-
object_init_ex(ret, ce);
1482+
if (object_init_ex(ret, ce) != SUCCESS) {
1483+
return ret;
1484+
}
14771485
soap_add_xml_ref(ret, data);
14781486
}
14791487
if (sdlType->model) {
@@ -1533,7 +1541,9 @@ static zval *to_zval_object_ex(zval *ret, encodeTypePtr type, xmlNodePtr data, z
15331541
return ret;
15341542
}
15351543

1536-
object_init_ex(ret, ce);
1544+
if (object_init_ex(ret, ce) != SUCCESS) {
1545+
return ret;
1546+
}
15371547
soap_add_xml_ref(ret, data);
15381548
trav = data->children;
15391549

ext/soap/tests/bugs/gh16259.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
GH-16259 (Soap segfault when classmap instantiation fails)
3+
--EXTENSIONS--
4+
soap
5+
--FILE--
6+
<?php
7+
abstract class CT_A1 {
8+
}
9+
class CT_A2 extends CT_A1 {
10+
}
11+
12+
$classMap = array("A1" => "CT_A1", "A2" => "CT_A2");
13+
$client = new SoapClient(__DIR__."/bug36575.wsdl", array("trace" => 1, "exceptions" => 0));
14+
$a2 = new CT_A2();
15+
$client->test($a2);
16+
$soapRequest = $client->__getLastRequest();
17+
18+
$server = new SoapServer(__DIR__."/bug36575.wsdl", array("classmap" => $classMap));
19+
$server->handle($soapRequest);
20+
?>
21+
--EXPECT--
22+
<?xml version="1.0" encoding="UTF-8"?>
23+
<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>

0 commit comments

Comments
 (0)