components/php/php56/patches/CVE-2015-6831_70168.patch
author Michael Nestler <Michael.Nestler@Oracle.COM>
Thu, 19 Nov 2015 22:52:15 -0800
changeset 5116 867d838118ad
permissions -rw-r--r--
22244227 problem in UTILITY/PHP 21577672 problem in UTILITY/PHP 22244239 problem in UTILITY/PHP 22244245 problem in UTILITY/PHP 22244247 problem in UTILITY/PHP 22244253 problem in UTILITY/PHP 22244256 problem in UTILITY/PHP 22244261 problem in UTILITY/PHP 22244265 problem in UTILITY/PHP 22244270 problem in UTILITY/PHP 22244277 problem in UTILITY/PHP 22244286 problem in UTILITY/PHP

# Source: upstream
# http://git.php.net/?p=php-src.git;a=commit;h=c2e197e4efc663ca55f393bf0e799848842286f3
# https://bugs.php.net/bug.php?id=70168
# Patch cleaned up to not make extraneous whitespace changes.

From c2e197e4efc663ca55f393bf0e799848842286f3 Mon Sep 17 00:00:00 2001
From: Stanislav Malyshev <[email protected]>
Date: Sat, 1 Aug 2015 21:12:38 -0700
Subject: [PATCH] Fix bug #70168 - Use After Free Vulnerability in
 unserialize() with SplObjectStorage

---
 ext/spl/spl_observer.c      | 68 +++++++++++++++++++++++----------------------
 ext/spl/tests/bug70168.phpt | 19 +++++++++++++
 2 files changed, 54 insertions(+), 33 deletions(-)
 create mode 100644 ext/spl/tests/bug70168.phpt

diff --git a/ext/spl/spl_observer.c b/ext/spl/spl_observer.c
index da9110b..5d94a3b 100644
--- a/ext/spl/spl_observer.c
+++ b/ext/spl/spl_observer.c
@@ -832,14 +832,15 @@ SPL_METHOD(SplObjectStorage, unserialize)
 		goto outexcept;
 	}
 
+	var_push_dtor(&var_hash, &pcount);
 	--p; /* for ';' */
 	count = Z_LVAL_P(pcount);
-		
+
 	while(count-- > 0) {
 		spl_SplObjectStorageElement *pelement;
 		char *hash;
 		int hash_len;
-		
+
 		if (*p != ';') {
 			goto outexcept;
 		}
@@ -903,6 +904,7 @@ SPL_METHOD(SplObjectStorage, 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/bug70168.phpt b/ext/spl/tests/bug70168.phpt
new file mode 100644
index 0000000..192f0f3
--- /dev/null
+++ b/ext/spl/tests/bug70168.phpt
@@ -0,0 +1,19 @@
+--TEST--
+SPL: Bug #70168 Use After Free Vulnerability in unserialize() with SplObjectStorage
+--FILE--
+<?php
+$inner = 'x:i:1;O:8:"stdClass":0:{};m:a:0:{}';
+$exploit = 'a:2:{i:0;C:16:"SplObjectStorage":'.strlen($inner).':{'.$inner.'}i:1;R:3;}';
+
+$data = unserialize($exploit);
+
+for($i = 0; $i < 5; $i++) {
+    $v[$i] = 'hi'.$i;
+}
+
+var_dump($data[1]);
+?>
+===DONE===
+--EXPECT--
+int(1)
+===DONE===
-- 
2.1.4