Skip to content

Fix segfault and assertion failure with refcounted props and arrays #12478

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
4 changes: 3 additions & 1 deletion ext/soap/php_encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -1561,10 +1561,12 @@ static zval *to_zval_object_ex(zval *ret, encodeTypePtr type, xmlNodePtr data, z
if (Z_TYPE_P(prop) != IS_ARRAY) {
/* Convert into array */
array_init(&arr);
Z_ADDREF_P(prop);
Z_TRY_ADDREF_P(prop);
add_next_index_zval(&arr, prop);
set_zval_property(ret, (char*)trav->name, &arr);
prop = &arr;
} else {
SEPARATE_ARRAY(prop);
}
/* Add array element */
add_next_index_zval(prop, &tmpVal);
Expand Down
51 changes: 51 additions & 0 deletions ext/soap/tests/bugs/segfault_assertion_props.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
--TEST--
Segfault and assertion failure with refcounted props and arrays
--INI--
soap.wsdl_cache_enabled=0
--EXTENSIONS--
soap
--FILE--
<?php
class TestSoapClient extends SoapClient {
function __doRequest($request, $location, $action, $version, $one_way = false): ?string {
return <<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<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>
<ns1:dotest2Response><res xsi:type="SOAP-ENC:Struct">
<a xsi:type="xsd:string">Hello</a>
<b xsi:type="xsd:string">World</b>
</res>
</ns1:dotest2Response></SOAP-ENV:Body></SOAP-ENV:Envelope>
EOF;
}
}

trait A {
public $a = [self::class . 'a'];
public $b = self::class . 'b';
}

class DummyClass {
use A;
}

$client = new TestSoapClient(__DIR__."/../classmap.wsdl", ['classmap' => ['Struct' => 'DummyClass']]);
var_dump($client->dotest2("???"));
?>
--EXPECT--
object(DummyClass)#2 (2) {
["a"]=>
array(2) {
[0]=>
string(11) "DummyClassa"
[1]=>
string(5) "Hello"
}
["b"]=>
array(2) {
[0]=>
string(11) "DummyClassb"
[1]=>
string(5) "World"
}
}