]> granicus.if.org Git - php/commitdiff
Fixed bug #70166 - Use After Free Vulnerability in unserialize() with SPLArrayObject
authorStanislav Malyshev <stas@php.net>
Sun, 2 Aug 2015 04:45:19 +0000 (21:45 -0700)
committerStanislav Malyshev <stas@php.net>
Sun, 2 Aug 2015 05:01:40 +0000 (22:01 -0700)
ext/spl/spl_array.c
ext/spl/tests/bug70166.phpt [new file with mode: 0644]

index a37eced00253e005366a7d5087e174572b28e547..86608c0d5296616327c50d93fe280d03b5dbba4a 100644 (file)
@@ -1777,6 +1777,7 @@ SPL_METHOD(Array, unserialize)
                goto outexcept;
        }
 
+       var_push_dtor(&var_hash, &pflags);
        --p; /* for ';' */
        flags = Z_LVAL_P(pflags);
        /* flags needs to be verified and we also need to verify whether the next
@@ -1800,6 +1801,7 @@ SPL_METHOD(Array, unserialize)
                if (!php_var_unserialize(&intern->array, &p, s + buf_len, &var_hash TSRMLS_CC)) {
                        goto outexcept;
                }
+               var_push_dtor(&var_hash, &intern->array);
        }
        if (*p != ';') {
                goto outexcept;
@@ -1818,6 +1820,7 @@ SPL_METHOD(Array, unserialize)
                goto outexcept;
        }
 
+       var_push_dtor(&var_hash, &pmembers);
        /* copy members */
        if (!intern->std.properties) {
                rebuild_object_properties(&intern->std);
diff --git a/ext/spl/tests/bug70166.phpt b/ext/spl/tests/bug70166.phpt
new file mode 100644 (file)
index 0000000..51a3596
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+SPL: Bug #70166 Use After Free Vulnerability in unserialize() with SPLArrayObject
+--FILE--
+<?php
+$inner = 'x:i:1;a:0:{};m:a:0:{}';
+$exploit = 'a:2:{i:0;C:11:"ArrayObject":'.strlen($inner).':{'.$inner.'}i:1;R:5;}';
+
+$data = unserialize($exploit);
+
+for($i = 0; $i < 5; $i++) {
+    $v[$i] = 'hi'.$i;
+}
+
+var_dump($data);
+?>
+===DONE===
+--EXPECTF--
+array(2) {
+  [0]=>
+  object(ArrayObject)#%d (1) {
+    ["storage":"ArrayObject":private]=>
+    array(0) {
+    }
+  }
+  [1]=>
+  array(0) {
+  }
+}
+===DONE===