]> granicus.if.org Git - php/commitdiff
Fixed bug #70661 (Use After Free Vulnerability in WDDX Packet Deserialization)
authorStanislav Malyshev <stas@php.net>
Mon, 28 Dec 2015 22:46:35 +0000 (14:46 -0800)
committerAnatol Belski <ab@php.net>
Mon, 4 Jan 2016 16:10:29 +0000 (17:10 +0100)
Conflicts:
ext/wddx/wddx.c

ext/wddx/tests/bug70661.phpt [new file with mode: 0644]
ext/wddx/wddx.c

diff --git a/ext/wddx/tests/bug70661.phpt b/ext/wddx/tests/bug70661.phpt
new file mode 100644 (file)
index 0000000..e068c20
--- /dev/null
@@ -0,0 +1,69 @@
+--TEST--
+Bug #70661 (Use After Free Vulnerability in WDDX Packet Deserialization)
+--SKIPIF--
+<?php
+if (!extension_loaded("wddx")) print "skip";
+?>
+--FILE--
+<?php
+$fakezval = ptr2str(1122334455);
+$fakezval .= ptr2str(0);
+$fakezval .= "\x00\x00\x00\x00";
+$fakezval .= "\x01";
+$fakezval .= "\x00";
+$fakezval .= "\x00\x00";
+
+$x = <<<EOT
+<?xml version='1.0'?>
+<wddxPacket version='1.0'>
+<header/>
+       <data>
+               <struct>
+                       <recordset rowCount='1' fieldNames='ryat'>
+                               <field name='ryat'>
+                                       <var name='php_class_name'>
+                                               <string>stdClass</string>
+                                       </var>
+                                       <null/>
+                               </field>
+                       </recordset>
+               </struct>       
+       </data>
+</wddxPacket>
+EOT;
+
+$y = wddx_deserialize($x);
+
+for ($i = 0; $i < 5; $i++) {
+       $v[$i] = $fakezval.$i;
+}
+
+var_dump($y);
+
+function ptr2str($ptr)
+{
+       $out = '';
+       
+       for ($i = 0; $i < 8; $i++) {
+               $out .= chr($ptr & 0xff);
+               $ptr >>= 8;
+       }
+       
+       return $out;
+}
+?>
+DONE
+--EXPECTF--
+array(1) {
+  [0]=>
+  array(1) {
+    ["ryat"]=>
+    array(2) {
+      ["php_class_name"]=>
+      string(8) "stdClass"
+      [0]=>
+      NULL
+    }
+  }
+}
+DONE
\ No newline at end of file
index 66328900844eb3675115e948c5e3474994298086..83b8f97294d01f29d0e92f96662c15d40abfbf2e 100644 (file)
@@ -908,7 +908,7 @@ static void php_wddx_pop_element(void *user_data, const XML_Char *name)
 
                                if (ent1->varname) {
                                        if (!strcmp(ent1->varname, PHP_CLASS_NAME_VAR) &&
-                                               Z_TYPE(ent1->data) == IS_STRING && Z_STRLEN(ent1->data)) {
+                                               Z_TYPE(ent1->data) == IS_STRING && Z_STRLEN(ent1->data) && ent2->type == ST_STRUCT) {
                                                zend_bool incomplete_class = 0;
 
                                                zend_str_tolower(Z_STRVAL(ent1->data), Z_STRLEN(ent1->data));