20017b
From b585a3aed7880a5fa5c18e2b838fc96f40e075bd Mon Sep 17 00:00:00 2001
20017b
From: Stanislav Malyshev <stas@php.net>
20017b
Date: Thu, 1 Jan 2015 16:19:05 -0800
20017b
Subject: [PATCH] Fix for bug #68710 (Use After Free Vulnerability in PHP's
20017b
 unserialize())
20017b
20017b
---
20017b
 NEWS                                     |  4 ++++
20017b
 ext/standard/tests/strings/bug68710.phpt | 25 +++++++++++++++++++++++++
20017b
 ext/standard/var_unserializer.c          |  4 ++--
20017b
 ext/standard/var_unserializer.re         |  2 +-
20017b
 4 files changed, 32 insertions(+), 3 deletions(-)
20017b
 create mode 100644 ext/standard/tests/strings/bug68710.phpt
20017b
20017b
diff --git a/ext/standard/tests/strings/bug68710.phpt b/ext/standard/tests/strings/bug68710.phpt
20017b
new file mode 100644
20017b
index 0000000..729a120
20017b
--- /dev/null
20017b
+++ b/ext/standard/tests/strings/bug68710.phpt
20017b
@@ -0,0 +1,25 @@
20017b
+--TEST--
20017b
+Bug #68710 Use after free vulnerability in unserialize() (bypassing the
20017b
+CVE-2014-8142 fix)
20017b
+--FILE--
20017b
+
20017b
+for ($i=4; $i<100; $i++) {
20017b
+    $m = new StdClass();
20017b
+
20017b
+    $u = array(1);
20017b
+
20017b
+    $m->aaa = array(1,2,&$u,4,5);
20017b
+    $m->bbb = 1;
20017b
+    $m->ccc = &$;;
20017b
+    $m->ddd = str_repeat("A", $i);
20017b
+
20017b
+    $z = serialize($m);
20017b
+    $z = str_replace("aaa", "123", $z);
20017b
+    $z = str_replace("bbb", "123", $z);
20017b
+    $y = unserialize($z);
20017b
+    $z = serialize($y);
20017b
+}
20017b
+?>
20017b
+===DONE===
20017b
+--EXPECTF--
20017b
+===DONE===
20017b
diff --git a/ext/standard/var_unserializer.c b/ext/standard/var_unserializer.c
20017b
index a12d2fa..f114080 100644
20017b
--- a/ext/standard/var_unserializer.c
20017b
+++ b/ext/standard/var_unserializer.c
20017b
@@ -309,7 +309,7 @@ static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, long
20017b
 		} else {
20017b
 			/* object properties should include no integers */
20017b
 			convert_to_string(key);
20017b
-			if (zend_symtable_find(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, (void **)&old_data)==SUCCESS) {
20017b
+			if (zend_hash_find(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, (void **)&old_data)==SUCCESS) {
20017b
 				var_push_dtor(var_hash, old_data);
20017b
 			}
20017b
 			zend_hash_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data,
20017b
diff --git a/ext/standard/var_unserializer.re b/ext/standard/var_unserializer.re
20017b
index 4cf1d10..f04fc74 100644
20017b
--- a/ext/standard/var_unserializer.re
20017b
+++ b/ext/standard/var_unserializer.re
20017b
@@ -315,7 +315,7 @@ static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, long
20017b
 		} else {
20017b
 			/* object properties should include no integers */
20017b
 			convert_to_string(key);
20017b
-			if (zend_symtable_find(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, (void **)&old_data)==SUCCESS) {
20017b
+			if (zend_hash_find(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, (void **)&old_data)==SUCCESS) {
20017b
 				var_push_dtor(var_hash, old_data);
20017b
 			}
20017b
 			zend_hash_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data,
20017b
-- 
20017b
2.1.4
20017b