|
| 1 | +--TEST-- |
| 2 | +GH-22895 (Heap use-after-free while encoding a Traversable with an illegal key) |
| 3 | +--CREDITS-- |
| 4 | +Amorsec |
| 5 | +--EXTENSIONS-- |
| 6 | +soap |
| 7 | +--FILE-- |
| 8 | +<?php |
| 9 | +class LocalSoapClient extends SoapClient |
| 10 | +{ |
| 11 | + public function __doRequest( |
| 12 | + $request, |
| 13 | + $location, |
| 14 | + $action, |
| 15 | + $version, |
| 16 | + $one_way = false |
| 17 | + ): ?string { |
| 18 | + return ''; |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +class ArrayKeyIterator implements Iterator |
| 23 | +{ |
| 24 | + private int $i = 0; |
| 25 | + |
| 26 | + public function current(): mixed |
| 27 | + { |
| 28 | + return new stdClass(); |
| 29 | + } |
| 30 | + |
| 31 | + public function key(): mixed |
| 32 | + { |
| 33 | + return ['illegal', 'key']; |
| 34 | + } |
| 35 | + |
| 36 | + public function next(): void |
| 37 | + { |
| 38 | + $this->i++; |
| 39 | + } |
| 40 | + |
| 41 | + public function rewind(): void |
| 42 | + { |
| 43 | + $this->i = 0; |
| 44 | + } |
| 45 | + |
| 46 | + public function valid(): bool |
| 47 | + { |
| 48 | + return $this->i < 2; |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +$client = new LocalSoapClient(null, [ |
| 53 | + 'location' => 'http://127.0.0.1/', |
| 54 | + 'uri' => 'urn:audit', |
| 55 | + 'trace' => 1, |
| 56 | +]); |
| 57 | + |
| 58 | +$multiple = new MultipleIterator(); |
| 59 | +$multiple->attachIterator(new ArrayIterator([0])); |
| 60 | + |
| 61 | +foreach ([$multiple, new ArrayKeyIterator()] as $iterator) { |
| 62 | + try { |
| 63 | + $client->__soapCall('audit', [new SoapVar($iterator, SOAP_ENC_ARRAY)]); |
| 64 | + } catch (TypeError $e) { |
| 65 | + echo $e::class, ': ', $e->getMessage(), PHP_EOL; |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +function gen($key) { |
| 70 | + yield $key => new stdClass(); |
| 71 | + yield 2 => new stdClass(); |
| 72 | +} |
| 73 | + |
| 74 | +set_error_handler(function ($errno, $errstr) { |
| 75 | + throw new Exception($errstr); |
| 76 | +}); |
| 77 | +foreach ([1.5, STDIN, null] as $key) { |
| 78 | + try { |
| 79 | + $client->__soapCall('audit', [new SoapVar(gen($key), SOAP_ENC_ARRAY)]); |
| 80 | + } catch (Exception $e) { |
| 81 | + echo $e::class, ': ', $e->getMessage(), PHP_EOL; |
| 82 | + } |
| 83 | +} |
| 84 | +restore_error_handler(); |
| 85 | + |
| 86 | +/* A key the encoder can use must still be serialized, without leaking. */ |
| 87 | +$client->__soapCall('audit', [new SoapVar(new ArrayIterator(['a' => 1]), SOAP_ENC_ARRAY)]); |
| 88 | +echo $client->__getLastRequest(); |
| 89 | +?> |
| 90 | +--EXPECTF-- |
| 91 | +TypeError: Cannot access offset of type array on array |
| 92 | +TypeError: Cannot access offset of type array on array |
| 93 | +Exception: Implicit conversion from float 1.5 to int loses precision |
| 94 | +Exception: Resource ID#%d used as offset, casting to integer (%d) |
| 95 | +Exception: Using null as an array offset is deprecated, use an empty string instead |
| 96 | +<?xml version="1.0" encoding="UTF-8"?> |
| 97 | +<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:audit" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:audit><param0 SOAP-ENC:arrayType="xsd:int[1]" xsi:type="SOAP-ENC:Array"><item xsi:type="xsd:int">1</item></param0></ns1:audit></SOAP-ENV:Body></SOAP-ENV:Envelope> |
0 commit comments