Skip to content

Commit 5cf78a5

Browse files
ext/soap: fix leak when load_wsdl_ex() fails to load
1 parent e50b8b0 commit 5cf78a5

2 files changed

Lines changed: 67 additions & 1 deletion

File tree

‎ext/soap/php_sdl.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,12 @@ static void load_wsdl_ex(zval *this_ptr, char *struri, sdlCtx *ctx, int include)
364364
xmlAttrPtr tmp = get_attribute(trav->properties, "location");
365365
if (tmp) {
366366
xmlChar *uri = schema_location_construct_uri(tmp);
367-
load_wsdl_ex(this_ptr, (char*)uri, ctx, 1);
367+
zend_try {
368+
load_wsdl_ex(this_ptr, (char*)uri, ctx, 1);
369+
} zend_catch {
370+
xmlFree(uri);
371+
zend_bailout();
372+
} zend_end_try();
368373
xmlFree(uri);
369374
}
370375

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
--TEST--
2+
Memory leak when load_wsdl_ex() fails
3+
--EXTENSIONS--
4+
soap
5+
--INI--
6+
soap.wsdl_cache_enabled=0
7+
--SKIPIF--
8+
<?php
9+
if (!file_exists(__DIR__ . "/../../../sapi/cli/tests/php_cli_server.inc")) {
10+
echo "skip sapi/cli/tests/php_cli_server.inc required but not found";
11+
}
12+
?>
13+
--FILE--
14+
<?php
15+
16+
include __DIR__ . "/../../../sapi/cli/tests/php_cli_server.inc";
17+
18+
$context = stream_context_create([
19+
'http' => ['header' => [
20+
"Authorization: Bar",
21+
"aUTHORIZATION: Baz",
22+
]],
23+
]);
24+
25+
$wsdl = <<<END
26+
<?xml version="1.0" encoding="utf-8"?>
27+
<definitions
28+
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
29+
xmlns="http://schemas.xmlsoap.org/wsdl/"
30+
>
31+
<import location="http://localhost:0/index.php"/>
32+
</definitions>
33+
END;
34+
35+
$server_code = "echo <<<END\n$wsdl\nEND;";
36+
php_cli_server_start($server_code);
37+
$wsdl_server_port = PHP_CLI_SERVER_PORT;
38+
39+
try {
40+
$client = new SoapClient("http://localhost:$wsdl_server_port", [
41+
'soap_version' => SOAP_1_1,
42+
'stream_context' => $context,
43+
]);
44+
} catch (SoapFault $e) {
45+
echo get_class($e) . ': ' . $e->getMessage() . "\n";
46+
echo "--- Raw Server Response Body ---\n";
47+
var_dump(@file_get_contents("http://localhost:$wsdl_server_port", false, $context));
48+
}
49+
50+
?>
51+
--EXPECT--
52+
SoapFault: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://localhost:0/index.php' : failed to load external entity "http://localhost:0/index.php"
53+
54+
--- Raw Server Response Body ---
55+
string(216) "<?xml version="1.0" encoding="utf-8"?>
56+
<definitions
57+
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
58+
xmlns="http://schemas.xmlsoap.org/wsdl/"
59+
>
60+
<import location="http://localhost:0/index.php"/>
61+
</definitions>"

0 commit comments

Comments
 (0)