Skip to content

Commit d7f9caf

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix GH-18640: heap-use-after-free ext/soap/php_encoding.c:299:32 in soap_check_zval_ref
2 parents 541620c + f8196a5 commit d7f9caf

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

ext/soap/php_encoding.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,6 +1924,11 @@ static xmlNodePtr to_xml_object(encodeTypePtr type, zval *data, int style, xmlNo
19241924
sdlAttributePtr attr;
19251925
zval *zattr, rv;
19261926

1927+
/* Attributes can't refer to other attributes as there's nothing to attach the href to. */
1928+
HashTable **ref_map = &SOAP_GLOBAL(ref_map);
1929+
HashTable *old_ref_map = *ref_map;
1930+
*ref_map = NULL;
1931+
19271932
ZEND_HASH_FOREACH_PTR(sdlType->attributes, attr) {
19281933
if (attr->name) {
19291934
zattr = get_zval_property(data, attr->name, &rv);
@@ -1953,6 +1958,8 @@ static xmlNodePtr to_xml_object(encodeTypePtr type, zval *data, int style, xmlNo
19531958
}
19541959
}
19551960
} ZEND_HASH_FOREACH_END();
1961+
1962+
*ref_map = old_ref_map;
19561963
}
19571964
}
19581965
if (style == SOAP_ENCODED) {
@@ -3055,6 +3062,12 @@ static xmlNodePtr to_xml_list(encodeTypePtr enc, zval *data, int style, xmlNodeP
30553062
ret = xmlNewDocNode(parent->doc, NULL, BAD_CAST("BOGUS"), NULL);
30563063
xmlAddChild(parent, ret);
30573064
FIND_ZVAL_NULL(data, ret, style);
3065+
3066+
/* Literals are unique and can't refer to other references via attributes. */
3067+
HashTable **ref_map = &SOAP_GLOBAL(ref_map);
3068+
HashTable *old_ref_map = *ref_map;
3069+
*ref_map = NULL;
3070+
30583071
if (Z_TYPE_P(data) == IS_ARRAY) {
30593072
zval *tmp;
30603073
smart_str list = {0};
@@ -3129,6 +3142,7 @@ static xmlNodePtr to_xml_list(encodeTypePtr enc, zval *data, int style, xmlNodeP
31293142
zval_ptr_dtor_str(&tmp);
31303143
}
31313144
}
3145+
*ref_map = old_ref_map;
31323146
return ret;
31333147
}
31343148

ext/soap/tests/bugs/gh18640.phpt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST---
2+
GH-18640 (heap-use-after-free ext/soap/php_encoding.c:299:32 in soap_check_zval_ref)
3+
--EXTENSIONS--
4+
soap
5+
--CREDITS--
6+
YuanchengJiang
7+
--FILE--
8+
<?php
9+
$wsdl = __DIR__."/bug35142.wsdl";
10+
11+
class TestSoapClient extends SoapClient {
12+
function __doRequest($request, $location, $action, $version, $one_way = 0): ?string {
13+
var_dump($request);
14+
return '';
15+
}
16+
}
17+
18+
$soapClient = new TestSoapClient($wsdl, ['trace' => 1, 'classmap' => ['logOnEvent' => 'LogOnEvent', 'events' => 'IVREvents']]);
19+
$timestamp = new LogOnEvent(); // Bogus!
20+
$logOffEvents[] = new LogOffEvent($timestamp);
21+
$logOffEvents[] = new LogOffEvent($timestamp);
22+
$ivrEvents = new IVREvents($logOffEvents);
23+
$result = $soapClient->PostEvents($ivrEvents);
24+
25+
class LogOffEvent {
26+
function __construct(public $timestamp) {
27+
$this->timestamp = $timestamp;
28+
}
29+
}
30+
31+
class LogOnEvent {
32+
}
33+
34+
class IVREvents {
35+
function __construct(public $logOffEvent) {
36+
}
37+
}
38+
?>
39+
--EXPECT--
40+
string(359) "<?xml version="1.0" encoding="UTF-8"?>
41+
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://testurl/Events" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="http://testurl/Message"><SOAP-ENV:Body><ns2:ivrEvents><ns2:logOffEvent/><ns2:logOffEvent/></ns2:ivrEvents></SOAP-ENV:Body></SOAP-ENV:Envelope>
42+
"

0 commit comments

Comments
 (0)