Skip to content

Commit 84e3004

Browse files
iluuu1994saundefined
authored andcommitted
GHSA-85c2-q967-79q5: [soap] Fix stale SOAP_GLOBAL(ref_map) pointer with Apache Map
Fixes GHSA-85c2-q967-79q5 Fixes CVE-2026-6722
1 parent 18edbc2 commit 84e3004

2 files changed

Lines changed: 63 additions & 1 deletion

File tree

ext/soap/php_encoding.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ static bool soap_check_xml_ref(zval *data, xmlNodePtr node)
365365
static void soap_add_xml_ref(zval *data, xmlNodePtr node)
366366
{
367367
if (SOAP_GLOBAL(ref_map)) {
368+
Z_TRY_ADDREF_P(data);
368369
zend_hash_index_update(SOAP_GLOBAL(ref_map), (zend_ulong)node, data);
369370
}
370371
}
@@ -3448,7 +3449,7 @@ void encode_reset_ns()
34483449
} else {
34493450
SOAP_GLOBAL(ref_map) = emalloc(sizeof(HashTable));
34503451
}
3451-
zend_hash_init(SOAP_GLOBAL(ref_map), 0, NULL, NULL, 0);
3452+
zend_hash_init(SOAP_GLOBAL(ref_map), 0, NULL, ZVAL_PTR_DTOR, 0);
34523453
}
34533454

34543455
void encode_finish()
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
--TEST--
2+
GHSA-85c2-q967-79q5: Stale SOAP_GLOBAL(ref_map) pointer with Apache Map
3+
--CREDITS--
4+
brettgervasoni
5+
--EXTENSIONS--
6+
soap
7+
--FILE--
8+
<?php
9+
10+
class Handler {
11+
public function test(...$args) {
12+
$GLOBALS['result'] = $args;
13+
}
14+
}
15+
16+
$envelope = <<<'XML'
17+
<?xml version="1.0" encoding="UTF-8"?>
18+
<soapenv:Envelope
19+
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
22+
23+
<soapenv:Body>
24+
<test>
25+
<map xsi:type="apache:Map" xmlns:apache="http://xml.apache.org/xml-soap">
26+
<item>
27+
<key>foo</key>
28+
<value id="stale"><object>bar</object></value>
29+
</item>
30+
<item>
31+
<key>foo</key>
32+
<value>baz</value>
33+
</item>
34+
</map>
35+
<stale href="#stale"/>
36+
</test>
37+
</soapenv:Body>
38+
</soapenv:Envelope>
39+
XML;
40+
41+
$s = new SoapServer(null, ['uri' => 'urn:a']);
42+
$s->setClass(Handler::class);
43+
$s->handle($envelope);
44+
var_dump($result);
45+
46+
?>
47+
--EXPECTF--
48+
<?xml version="1.0" encoding="UTF-8"?>
49+
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:a" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:testResponse><return xsi:nil="true"/></ns1:testResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
50+
array(2) {
51+
[0]=>
52+
array(1) {
53+
["foo"]=>
54+
string(3) "baz"
55+
}
56+
[1]=>
57+
object(stdClass)#%d (1) {
58+
["object"]=>
59+
string(3) "bar"
60+
}
61+
}

0 commit comments

Comments
 (0)