Blame SOURCES/php-5.5.21-CVE-2015-2787.patch

8bac60
From 646572d6d3847d68124b03936719f60936b49a38 Mon Sep 17 00:00:00 2001
8bac60
From: Stanislav Malyshev <stas@php.net>
8bac60
Date: Tue, 17 Mar 2015 13:20:22 -0700
8bac60
Subject: [PATCH] Fixed bug #68976 - Use After Free Vulnerability in
8bac60
 unserialize()
8bac60
8bac60
---
8bac60
 NEWS                             |  3 +-
8bac60
 ext/standard/var_unserializer.c  | 63 ++++++++++++++++++++--------------------
8bac60
 ext/standard/var_unserializer.re |  1 +
8bac60
 3 files changed, 35 insertions(+), 32 deletions(-)
8bac60
8bac60
diff --git a/ext/standard/var_unserializer.c b/ext/standard/var_unserializer.c
8bac60
index f114080..ee0cac4 100644
8bac60
--- a/ext/standard/var_unserializer.c
8bac60
+++ b/ext/standard/var_unserializer.c
8bac60
@@ -347,6 +347,7 @@ static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, long
8bac60
 			zend_hash_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data,
8bac60
 					sizeof data, NULL);
8bac60
 		}
8bac60
+		var_push_dtor(var_hash, &data);
8bac60
 		
8bac60
 		zval_dtor(key);
8bac60
 		FREE_ZVAL(key);
8bac60
diff --git a/ext/standard/var_unserializer.re b/ext/standard/var_unserializer.re
8bac60
index f04fc74..abac77c 100644
8bac60
--- a/ext/standard/var_unserializer.re
8bac60
+++ b/ext/standard/var_unserializer.re
8bac60
@@ -353,6 +353,7 @@ static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, long
8bac60
 			zend_hash_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data,
8bac60
 					sizeof data, NULL);
8bac60
 		}
8bac60
+		var_push_dtor(var_hash, &data);
8bac60
 		
8bac60
 		zval_dtor(key);
8bac60
 		FREE_ZVAL(key);
8bac60
From 8b14d3052ffcffa17d6e2be652f20e18f8f562ad Mon Sep 17 00:00:00 2001
8bac60
From: Stanislav Malyshev <stas@php.net>
8bac60
Date: Tue, 17 Mar 2015 17:03:46 -0700
8bac60
Subject: [PATCH] add test for bug #68976
8bac60
8bac60
---
8bac60
 ext/standard/tests/serialize/bug68976.phpt | 37 ++++++++++++++++++++++++++++++
8bac60
 1 file changed, 37 insertions(+)
8bac60
 create mode 100644 ext/standard/tests/serialize/bug68976.phpt
8bac60
8bac60
diff --git a/ext/standard/tests/serialize/bug68976.phpt b/ext/standard/tests/serialize/bug68976.phpt
8bac60
new file mode 100644
8bac60
index 0000000..a79a953
8bac60
--- /dev/null
8bac60
+++ b/ext/standard/tests/serialize/bug68976.phpt
8bac60
@@ -0,0 +1,37 @@
8bac60
+--TEST--
8bac60
+Bug #68976 Use After Free Vulnerability in unserialize()
8bac60
+--FILE--
8bac60
+
8bac60
+class evilClass {
8bac60
+	public $name;
8bac60
+	function __wakeup() {
8bac60
+		unset($this->name);
8bac60
+	}
8bac60
+}
8bac60
+
8bac60
+$fakezval = pack(
8bac60
+    'IIII',
8bac60
+    0x00100000,
8bac60
+    0x00000400,
8bac60
+    0x00000000,
8bac60
+    0x00000006 
8bac60
+);
8bac60
+
8bac60
+$data = unserialize('a:2:{i:0;O:9:"evilClass":1:{s:4:"name";a:2:{i:0;i:1;i:1;i:2;}}i:1;R:4;}');
8bac60
+
8bac60
+for($i = 0; $i < 5; $i++) {
8bac60
+    $v[$i] = $fakezval.$i;
8bac60
+}
8bac60
+
8bac60
+var_dump($data);
8bac60
+?>
8bac60
+===DONE===
8bac60
+--EXPECTF--
8bac60
+array(2) {
8bac60
+  [0]=>
8bac60
+  object(evilClass)#1 (0) {
8bac60
+  }
8bac60
+  [1]=>
8bac60
+  int(1)
8bac60
+}
8bac60
+===DONE===