Skip to content

Fix GH-12392: Segmentation fault on SoapClient::__getTypes #12409

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
18 changes: 12 additions & 6 deletions ext/soap/php_schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -2261,17 +2261,23 @@ static void schema_type_fixup(sdlCtx *ctx, sdlTypePtr type)
schema_content_model_fixup(ctx, type->model);
}
if (type->attributes) {
zend_string *str_key;
zend_ulong index;
HashPosition pos;
zend_hash_internal_pointer_reset_ex(type->attributes, &pos);

ZEND_HASH_FOREACH_KEY_PTR(type->attributes, index, str_key, attr) {
if (str_key) {
while ((attr = zend_hash_get_current_data_ptr_ex(type->attributes, &pos)) != NULL) {
zend_string *str_key;
zend_ulong index;

if (zend_hash_get_current_key_ex(type->attributes, &str_key, &index, &pos) == HASH_KEY_IS_STRING) {
schema_attribute_fixup(ctx, attr);
zend_result result = zend_hash_move_forward_ex(type->attributes, &pos);
ZEND_ASSERT(result == SUCCESS);
} else {
schema_attributegroup_fixup(ctx, attr, type->attributes);
zend_hash_index_del(type->attributes, index);
zend_result result = zend_hash_index_del(type->attributes, index);
ZEND_ASSERT(result == SUCCESS);
}
} ZEND_HASH_FOREACH_END();
}
}
}

Expand Down
28 changes: 28 additions & 0 deletions ext/soap/tests/gh12392.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
GH-12392 (Segmentation fault on SoapClient::__getTypes)
--EXTENSIONS--
soap
--FILE--
<?php

$client = new SoapClient(__DIR__ . "/gh12392.wsdl", ['cache_wsdl' => WSDL_CACHE_NONE]);
echo 'Client created!' . "\n";

$types = $client->__getTypes();
echo 'Got types!' . "\n";

var_dump($types);

?>
--EXPECT--
Client created!
Got types!
array(1) {
[0]=>
string(62) "struct dummy {
string foo;
string a;
string b;
string c;
}"
}
61 changes: 61 additions & 0 deletions ext/soap/tests/gh12392.wsdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version='1.0' encoding='UTF-8'?>
<wsdl:definitions
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
targetNamespace="http://xoev.de/schemata/xzufi/2_2_0">
<wsdl:types>
<xs:schema xmlns:ns="http://php.net" targetNamespace="http://php.net">
<xs:attributeGroup name="c">
<xs:attribute name="c" type="string" />
</xs:attributeGroup>

<xs:attributeGroup name="b">
<xs:attribute name="b" type="string" />
</xs:attributeGroup>

<xs:attributeGroup name="a">
<xs:attribute name="a" type="string" />
<xs:attributeGroup ref="ns:b" />
</xs:attributeGroup>

<xs:complexType name="dummy">
<xs:sequence>
<xs:element name="foo" type="string" />
</xs:sequence>
<xs:attributeGroup ref="ns:a" />
<xs:attributeGroup ref="ns:c" />
</xs:complexType>
</xs:schema>
</wsdl:types>

<!-- Below is a shortened copy of the test.wsdl, doesn't matter, only the types matter -->

<message name="AddRequest">
<part name="x" type="xs:double" />
</message>

<portType name="TestServicePortType">
<operation name="Add">
<input message="tns:AddRequest" />
</operation>
</portType>

<binding name="TestServiceBinding" type="tns:TestServicePortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="Add">
<soap:operation soapAction="Add" style="rpc" />
<input>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
</operation>
</binding>

<service name="TestService">
<port name="TestServicePort" binding="tns:TestServiceBinding">
<soap:address location="http://linuxsrv.home/~dmitry/soap/soap_server.php" />
</port>
</service>

</wsdl:definitions>