[php-src] PHP-8.2: Fix GHSA-cj93-vc83-wgqv

From: Date: Tue, 22 Sep 2026 08:54:12 +0000
Subject: [php-src] PHP-8.2: Fix GHSA-cj93-vc83-wgqv
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-141374@lists.php.net to get a copy of this message
Author: Nora Dossche (ndossche) Committer: Jakub Zelenka (bukka) Date: 2026-09-18T22:26:47+02:00 Commit: https://github.com/php/php-src/commit/b11bd1d9390bb203684e3d4aa5e1104ea842de6f Raw diff: https://github.com/php/php-src/commit/b11bd1d9390bb203684e3d4aa5e1104ea842de6f.diff Fix GHSA-cj93-vc83-wgqv Co-authored-by: Jakub Zelenka <bukka@php.net> Changed paths: A ext/soap/tests/bugs/GHSA-cj93-vc83-wgqv.phpt M ext/soap/php_http.c Diff: diff --git a/ext/soap/php_http.c b/ext/soap/php_http.c index 00aa54c83efd..ad2a3a8b06fb 100644 --- a/ext/soap/php_http.c +++ b/ext/soap/php_http.c @@ -1144,7 +1144,7 @@ int make_http_soap_request(zval *this_ptr, char *t = ZSTR_VAL(phpurl->path); char *p = strrchr(t, '/'); if (p) { - zend_string *s = zend_string_alloc((p - t) + ZSTR_LEN(new_url->path) + 2, 0); + zend_string *s = zend_string_safe_alloc(1, p - t, ZSTR_LEN(new_url->path) + 2, 0); strncpy(ZSTR_VAL(s), t, (p - t) + 1); ZSTR_VAL(s)[(p - t) + 1] = 0; strcat(ZSTR_VAL(s), ZSTR_VAL(new_url->path)); @@ -1435,7 +1435,8 @@ static zend_string* get_http_body(php_stream *stream, int close, char *headers) { zend_string *http_buf = NULL; char *header; - int header_close = close, header_chunked = 0, header_length = 0, http_buf_size = 0; + int header_close = close, header_chunked = 0, header_length = 0; + size_t http_buf_size = 0; if (!close) { header = get_http_header_value(headers, "Connection: "); @@ -1465,14 +1466,14 @@ static zend_string* get_http_body(php_stream *stream, int close, char *headers) done = FALSE; while (!done) { - int buf_size = 0; + unsigned int buf_size = 0; php_stream_gets(stream, headerbuf, sizeof(headerbuf)); if (sscanf(headerbuf, "%x", &buf_size) > 0 ) { if (buf_size > 0) { size_t len_size = 0; - if (http_buf_size + buf_size + 1 < 0) { + if (buf_size >= ZSTR_MAX_LEN - http_buf_size) { if (http_buf) { zend_string_release_ex(http_buf, 0); } @@ -1480,7 +1481,7 @@ static zend_string* get_http_body(php_stream *stream, int close, char *headers) } if (http_buf) { - http_buf = zend_string_realloc(http_buf, http_buf_size + buf_size, 0); + http_buf = zend_string_safe_realloc(http_buf, 1, http_buf_size, buf_size, false); } else { http_buf = zend_string_alloc(buf_size, 0); } @@ -1539,7 +1540,7 @@ static zend_string* get_http_body(php_stream *stream, int close, char *headers) } } else if (header_length) { - if (header_length < 0 || header_length >= INT_MAX) { + if (header_length < 0 || header_length >= ZSTR_MAX_LEN) { return NULL; } http_buf = zend_string_alloc(header_length, 0); @@ -1554,7 +1555,11 @@ static zend_string* get_http_body(php_stream *stream, int close, char *headers) do { ssize_t len_read; if (http_buf) { - http_buf = zend_string_realloc(http_buf, http_buf_size + 4096, 0); + if (UNEXPECTED(http_buf_size >= ZSTR_MAX_LEN - 4096)) { + zend_string_efree(http_buf); + return NULL; + } + http_buf = zend_string_realloc(http_buf, http_buf_size + 4096, false); } else { http_buf = zend_string_alloc(4096, 0); } diff --git a/ext/soap/tests/bugs/GHSA-cj93-vc83-wgqv.phpt b/ext/soap/tests/bugs/GHSA-cj93-vc83-wgqv.phpt new file mode 100644 index 000000000000..8813d956ec5a --- /dev/null +++ b/ext/soap/tests/bugs/GHSA-cj93-vc83-wgqv.phpt @@ -0,0 +1,99 @@ +--TEST-- +GHSA-cj93-vc83-wgqv +--INI-- +soap.wsdl_cache_enabled=0 +memory_limit=-1 +--EXTENSIONS-- +soap +--CONFLICTS-- +all +--SKIPIF-- +<?php +require __DIR__..'/../../../standard/tests/http/server.inc'; +http_server_skipif(); +if (getenv("SKIP_SLOW_TESTS")) die('skip slow test'); +if (!getenv("SOAP_RUN_RESOURCE_HEAVY_TESTS")) die("skip SOAP resource-heavy test"); +if (PHP_INT_SIZE == 4) die('skip not for 32-bit systems due to memory constraints'); + +if (!file_exists('/proc/meminfo')) { + die('skip Cannot check free RAM from /proc/meminfo on this platform'); +} + +$free_ram = 0; +if ($f = fopen("/proc/meminfo","r")) { + while (!feof($f)) { + if (preg_match('/MemFree[^\d]*(\d+)/i', fgets($f), $m)) { + $free_ram = max($free_ram, $m[1]/1024/1024); + if ($free_ram > 4) { + $enough_free_ram = true; + } + } + } +} + +if (empty($enough_free_ram)) { + die(sprintf("skip need +4G free RAM, but only %01.2f available", $free_ram)); +} +--FILE-- +<?php +require __DIR__.'/../../../standard/tests/http/server.inc'; + +function chunk_body($body, $n) +{ + $chunks = str_split($body, $n); + $chunks[] = ''; + + foreach ($chunks as $k => $v) { + $chunks[$k] = sprintf("%08x\r\n%s\r\n", strlen($v), $v); + } + + return join('', $chunks); +} + +$wsdl = file_get_contents(__DIR__.'/../server030.wsdl'); + +$soap = <<<EOF +<?xml version="1.0" encoding="UTF-8"?> +<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://testuri.org" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:getItemsResponse><getItemsReturn SOAP-ENC:arrayType="ns1:Item[10]" xsi:type="ns1:ItemArray"><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text0</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text1</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text2</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text3</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text4</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text5</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text6</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text7</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text8</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text9</text></item></getItemsReturn></ns1:getItemsResponse></SOAP-ENV:Body></SOAP-ENV:Envelope> +EOF; + +$responses = [ + "data://text/plain,HTTP/1.1 200 OK\r\n". + "Content-Type: text/xml;charset=utf-8\r\n". + "Transfer-Encoding: \t chunked\t \r\n". + "Connection: close\r\n". + "\r\n". + chunk_body($wsdl, 64), + "data://text/plain,HTTP/1.1 200 OK\r\n". + "Content-Type: text/xml;charset=utf-8\r\n". + "Transfer-Encoding: \t chunked\t \r\n". + "Connection: close\r\n". + "\r\n". + /* The second chunk only needs its size header: the reallocation for it + * happens before its body is read, so the overflow triggers on the first + * read into the undersized buffer.. */ + sprintf("%08x\r\n", 0x7fffffff).str_repeat('x', 0x7fffffff)."\r\n" . + sprintf("%08x\r\n", 0x7fffffff)."xxxx", +]; + + +['pid' => $pid, 'uri' => $uri] = http_server($responses); + +$options = [ + 'trace' => false, + 'location' => $uri, +]; + +$client = new SoapClient($uri, $options); + +$client->getItems(); + +http_server_kill($pid); + +--EXPECTF-- +Fatal error: Uncaught SoapFault exception: [HTTP] Error Fetching http body, No Content-Length, connection closed or chunked data in %s:%d +Stack trace: +#0 [internal function]: SoapClient->__doRequest('<?xml version="...', '%s', 'http://testuri.....', 1, false) +#1 %s(%d): SoapClient->__call('getItems', Array) +#2 {main} + thrown in %s on line %d

« previous php.cvs (#141374) next »