|
|
20017b |
From 630f9c33c23639de85c3fd306b209b538b73b4c9 Mon Sep 17 00:00:00 2001
|
|
|
20017b |
From: Stanislav Malyshev <stas@php.net>
|
|
|
20017b |
Date: Thu, 11 Dec 2014 19:28:32 -0800
|
|
|
20017b |
Subject: [PATCH] Fix bug #68594 - Use after free vulnerability in
|
|
|
20017b |
unserialize()
|
|
|
20017b |
|
|
|
20017b |
---
|
|
|
20017b |
NEWS | 2 +
|
|
|
20017b |
ext/standard/tests/serialize/bug68594.phpt | 23 ++++++++++
|
|
|
20017b |
ext/standard/var_unserializer.c | 68 ++++++++++++++++--------------
|
|
|
20017b |
ext/standard/var_unserializer.re | 3 ++
|
|
|
20017b |
4 files changed, 64 insertions(+), 32 deletions(-)
|
|
|
20017b |
create mode 100644 ext/standard/tests/serialize/bug68594.phpt
|
|
|
20017b |
|
|
|
20017b |
diff --git a/ext/standard/tests/serialize/bug68594.phpt b/ext/standard/tests/serialize/bug68594.phpt
|
|
|
20017b |
new file mode 100644
|
|
|
20017b |
index 0000000..60fc7a7
|
|
|
20017b |
--- /dev/null
|
|
|
20017b |
+++ b/ext/standard/tests/serialize/bug68594.phpt
|
|
|
20017b |
@@ -0,0 +1,23 @@
|
|
|
20017b |
+--TEST--
|
|
|
20017b |
+Bug #68545 Use after free vulnerability in unserialize()
|
|
|
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("bbb", "aaa", $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 f6f31bd..a12d2fa 100644
|
|
|
20017b |
--- a/ext/standard/var_unserializer.c
|
|
|
20017b |
+++ b/ext/standard/var_unserializer.c
|
|
|
20017b |
@@ -309,6 +309,9 @@ 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 |
+ var_push_dtor(var_hash, old_data);
|
|
|
20017b |
+ }
|
|
|
20017b |
zend_hash_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data,
|
|
|
20017b |
sizeof data, NULL);
|
|
|
20017b |
}
|
|
|
20017b |
diff --git a/ext/standard/var_unserializer.re b/ext/standard/var_unserializer.re
|
|
|
20017b |
index 7afef6a..4cf1d10 100644
|
|
|
20017b |
--- a/ext/standard/var_unserializer.re
|
|
|
20017b |
+++ b/ext/standard/var_unserializer.re
|
|
|
20017b |
@@ -315,6 +315,9 @@ 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 |
+ var_push_dtor(var_hash, old_data);
|
|
|
20017b |
+ }
|
|
|
20017b |
zend_hash_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data,
|
|
|
20017b |
sizeof data, NULL);
|
|
|
20017b |
}
|
|
|
20017b |
--
|
|
|
20017b |
2.1.4
|
|
|
20017b |
|