Skip to content

Commit f8196a5

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

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ PHP NEWS
2525
return value check). (nielsdos, botovq)
2626
. Fix error return check of EVP_CIPHER_CTX_ctrl(). (nielsdos)
2727

28+
- SOAP:
29+
. Fixed bug GH-18640 (heap-use-after-free ext/soap/php_encoding.c:299:32
30+
in soap_check_zval_ref). (nielsdos)
31+
2832
- Sockets:
2933
. Fix some potential crashes on incorrect argument value. (nielsdos)
3034

ext/soap/php_encoding.c

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

1952+
/* Attributes can't refer to other attributes as there's nothing to attach the href to. */
1953+
HashTable **ref_map = &SOAP_GLOBAL(ref_map);
1954+
HashTable *old_ref_map = *ref_map;
1955+
*ref_map = NULL;
1956+
19521957
ZEND_HASH_FOREACH_PTR(sdlType->attributes, attr) {
19531958
if (attr->name) {
19541959
zattr = get_zval_property(data, attr->name, &rv);
@@ -1978,6 +1983,8 @@ static xmlNodePtr to_xml_object(encodeTypePtr type, zval *data, int style, xmlNo
19781983
}
19791984
}
19801985
} ZEND_HASH_FOREACH_END();
1986+
1987+
*ref_map = old_ref_map;
19811988
}
19821989
}
19831990
if (style == SOAP_ENCODED) {
@@ -3060,6 +3067,12 @@ static xmlNodePtr to_xml_list(encodeTypePtr enc, zval *data, int style, xmlNodeP
30603067
ret = xmlNewNode(NULL, BAD_CAST("BOGUS"));
30613068
xmlAddChild(parent, ret);
30623069
FIND_ZVAL_NULL(data, ret, style);
3070+
3071+
/* Literals are unique and can't refer to other references via attributes. */
3072+
HashTable **ref_map = &SOAP_GLOBAL(ref_map);
3073+
HashTable *old_ref_map = *ref_map;
3074+
*ref_map = NULL;
3075+
30633076
if (Z_TYPE_P(data) == IS_ARRAY) {
30643077
zval *tmp;
30653078
smart_str list = {0};
@@ -3134,6 +3147,7 @@ static xmlNodePtr to_xml_list(encodeTypePtr enc, zval *data, int style, xmlNodeP
31343147
zval_ptr_dtor_str(&tmp);
31353148
}
31363149
}
3150+
*ref_map = old_ref_map;
31373151
return ret;
31383152
}
31393153

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)