Skip to content

Commit 01d6160

Browse files
committed
Fix segfault and assertion failure with refcounted props and arrays
Closes GH-12478.
1 parent abf562c commit 01d6160

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ PHP NEWS
2828
Fault). (nielsdos)
2929
. Fixed bug #67617 (SOAP leaves incomplete cache file on ENOSPC). (nielsdos)
3030
. Fix incorrect uri check in SOAP caching. (nielsdos)
31+
. Fix segfault and assertion failure with refcounted props and arrays.
32+
(nielsdos)
3133

3234
- XSL:
3335
. Add missing module dependency. (nielsdos)

ext/soap/php_encoding.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -1561,10 +1561,12 @@ static zval *to_zval_object_ex(zval *ret, encodeTypePtr type, xmlNodePtr data, z
15611561
if (Z_TYPE_P(prop) != IS_ARRAY) {
15621562
/* Convert into array */
15631563
array_init(&arr);
1564-
Z_ADDREF_P(prop);
1564+
Z_TRY_ADDREF_P(prop);
15651565
add_next_index_zval(&arr, prop);
15661566
set_zval_property(ret, (char*)trav->name, &arr);
15671567
prop = &arr;
1568+
} else {
1569+
SEPARATE_ARRAY(prop);
15681570
}
15691571
/* Add array element */
15701572
add_next_index_zval(prop, &tmpVal);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
--TEST--
2+
Segfault and assertion failure with refcounted props and arrays
3+
--INI--
4+
soap.wsdl_cache_enabled=0
5+
--EXTENSIONS--
6+
soap
7+
--FILE--
8+
<?php
9+
class TestSoapClient extends SoapClient {
10+
function __doRequest($request, $location, $action, $version, $one_way = false): ?string {
11+
return <<<EOF
12+
<?xml version="1.0" encoding="UTF-8"?>
13+
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.nothing.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body>
14+
<ns1:dotest2Response><res xsi:type="SOAP-ENC:Struct">
15+
<a xsi:type="xsd:string">Hello</a>
16+
<b xsi:type="xsd:string">World</b>
17+
</res>
18+
</ns1:dotest2Response></SOAP-ENV:Body></SOAP-ENV:Envelope>
19+
EOF;
20+
}
21+
}
22+
23+
trait A {
24+
public $a = [self::class . 'a'];
25+
public $b = self::class . 'b';
26+
}
27+
28+
class DummyClass {
29+
use A;
30+
}
31+
32+
$client = new TestSoapClient(__DIR__."/../classmap.wsdl", ['classmap' => ['Struct' => 'DummyClass']]);
33+
var_dump($client->dotest2("???"));
34+
?>
35+
--EXPECT--
36+
object(DummyClass)#2 (2) {
37+
["a"]=>
38+
array(2) {
39+
[0]=>
40+
string(11) "DummyClassa"
41+
[1]=>
42+
string(5) "Hello"
43+
}
44+
["b"]=>
45+
array(2) {
46+
[0]=>
47+
string(11) "DummyClassb"
48+
[1]=>
49+
string(5) "World"
50+
}
51+
}

0 commit comments

Comments
 (0)