php-src icon indicating copy to clipboard operation
php-src copied to clipboard

ext/soap: get_doc_function(): missing NULL check when request Body has fewer elements than declared WSDL parameters

Open cxxz16 opened this issue 1 month ago • 0 comments

Description

Category: NULL pointer dereference (SEGV READ @0x10); CWE-476. Context: document-style SoapServer; the WSDL operation declares two request elements (tns:a, tns:b) while the SOAP request Body contains only the first one.

Observed: ASan reports SEGV READ at address 0x10 in get_doc_function (ext/soap/soap.c:4474), reached via find_function (soap.c:3289) ← deserialize_function_call ← SoapServer::handle.

Relevant source: ext/soap/soap.c:4474 (node->name compared in a loop whose advance is node = node->next without a NULL check), :4487 (same pattern).

Source assessment: after the last Body element is consumed, node becomes NULL on the next advance, and the following iteration dereferences node->name to match it against the remaining declared parameter.

Expected: stop matching when node == NULL and report a controlled "missing parameter" fault. Evidence: asan/SOAP-01-docfunc-null-deref.asan.txt. PoC: poc/ (poc.php + test.wsdl; the server class TestService::Test($a,$b) matches the two declared parts; the request Body carries only tns:a).

poc.php

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema"
             xmlns:tns="http://test-uri"
             targetNamespace="http://test-uri">
  <types>
    <xsd:schema targetNamespace="http://test-uri" elementFormDefault="qualified">
      <xsd:element name="a" type="xsd:string"/>
      <xsd:element name="b" type="xsd:string"/>
    </xsd:schema>
  </types>
  <message name="TestRequest">
    <part name="a" element="tns:a"/>
    <part name="b" element="tns:b"/>
  </message>
  <message name="TestResponse">
    <part name="r" element="tns:a"/>
  </message>
  <portType name="TestPortType">
    <operation name="Test">
      <input message="tns:TestRequest"/>
      <output message="tns:TestResponse"/>
    </operation>
  </portType>
  <binding name="TestBinding" type="tns:TestPortType">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="Test">
      <soap:operation soapAction="http://test-uri/Test"/>
      <input><soap:body use="literal"/></input>
      <output><soap:body use="literal"/></output>
    </operation>
  </binding>
  <service name="TestService">
    <port name="TestPort" binding="tns:TestBinding">
      <soap:address location="http://localhost/test"/>
    </port>
  </service>
</definitions>

SOAP-01-docfunc-null-deref.asan.txt

PHP Version

Component: ext/soap in php-src master, commit b9ea38ef639f5b9bbb67d27834be9c52b922520b (cloned 2026-10-21).
PHP: 8.7.0-dev (cli), NTS.
Platform: Linux x86-64 (Ubuntu 22.04 container, Docker).
Sanitizer: AddressSanitizer (-fsanitize=address -g -O1).
Configure: --disable-all --enable-cli --enable-soap (plus phar/zlib/dom/simplexml/fileinfo/mbstring/sqlite3/openssl/curl/mysqli/pdo/pdo_pgsql/snmp/ftp in the shared image).

Recorded runtime environment:
  USE_ZEND_ALLOC=0
  ZEND_DONT_UNLOAD_MODULES=1
  ASAN_OPTIONS=abort_on_error=0:detect_leaks=0

Operating System

No response

cxxz16 avatar Oct 31 '26 16:10 cxxz16