Skip to content

Commit 026bb4e

Browse files
ext/soap: fix leak when load_wsdl_ex() fails to load (#24066)
1 parent 6abb600 commit 026bb4e

4 files changed

Lines changed: 32 additions & 1 deletion

File tree

‎NEWS‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ PHP NEWS
182182
- SOAP:
183183
. Fixed bug GH-22895 (Heap use-after-free while encoding a Traversable with
184184
an illegal key). (David Carlier)
185+
. Fixed memory leak when load_wsdl_ex() failed to load. (DanielEScherzer)
185186

186187
- Sockets:
187188
. Fixed socket_select() silently truncating sets larger than FD_SETSIZE on

‎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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
load_wsdl_ex() leaks the import location if imported WSDL fails to load
3+
--EXTENSIONS--
4+
soap
5+
--INI--
6+
soap.wsdl_cache_enabled=0
7+
--FILE--
8+
<?php
9+
10+
try {
11+
$client = new SoapClient(__DIR__ . '/load_wsdl_ex-failure-leak.wsdl');
12+
} catch (SoapFault $e) {
13+
echo get_class($e) . ': ' . $e->getMessage() . "\n";
14+
}
15+
16+
?>
17+
--EXPECTF--
18+
SoapFault: SOAP-ERROR: Parsing WSDL: Couldn't load from '%sload_wsdl_ex-failure-leak-missing.wsdl' : %s
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<definitions
3+
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
4+
xmlns="http://schemas.xmlsoap.org/wsdl/"
5+
>
6+
<import location="load_wsdl_ex-failure-leak-missing.wsdl"/>
7+
</definitions>

0 commit comments

Comments
 (0)