af9dc8
From 7b1898183032eeabc64a086ff040af991cebcd93 Mon Sep 17 00:00:00 2001
af9dc8
From: Stanislav Malyshev <stas@php.net>
af9dc8
Date: Sat, 31 Jan 2015 22:40:08 -0800
af9dc8
Subject: [PATCH] Fix bug #68942 (Use after free vulnerability in unserialize()
af9dc8
 with DateTimeZone)
af9dc8
af9dc8
Conflicts:
af9dc8
	ext/date/php_date.c
af9dc8
---
af9dc8
 ext/date/php_date.c            | 10 +++-------
af9dc8
 ext/date/tests/bug68942_2.phpt |  9 +++++++++
af9dc8
 2 files changed, 12 insertions(+), 7 deletions(-)
af9dc8
 create mode 100644 ext/date/tests/bug68942_2.phpt
af9dc8
af9dc8
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
af9dc8
index 92e9480..08bfd08 100644
af9dc8
--- a/ext/date/php_date.c
af9dc8
+++ b/ext/date/php_date.c
af9dc8
@@ -2521,12 +2521,9 @@ static int php_date_initialize_from_hash(php_date_obj **dateobj, HashTable *myht
af9dc8
 	timelib_tzinfo   *tzi;
af9dc8
 	php_timezone_obj *tzobj;
af9dc8
 
af9dc8
-	if (zend_hash_find(myht, "date", 5, (void**) &z_date) == SUCCESS) {
af9dc8
-		convert_to_string(*z_date);
af9dc8
-		if (zend_hash_find(myht, "timezone_type", 14, (void**) &z_timezone_type) == SUCCESS) {
af9dc8
-			convert_to_long(*z_timezone_type);
af9dc8
-			if (zend_hash_find(myht, "timezone", 9, (void**) &z_timezone) == SUCCESS) {
af9dc8
-				convert_to_string(*z_timezone);
af9dc8
+	if (zend_hash_find(myht, "date", 5, (void**) &z_date) == SUCCESS && Z_TYPE_PP(z_date) == IS_STRING) {
af9dc8
+		if (zend_hash_find(myht, "timezone_type", 14, (void**) &z_timezone_type) == SUCCESS && Z_TYPE_PP(z_timezone_type) == IS_LONG) {
af9dc8
+			if (zend_hash_find(myht, "timezone", 9, (void**) &z_timezone) == SUCCESS && Z_TYPE_PP(z_timezone) == IS_STRING) {
af9dc8
 
af9dc8
 				switch (Z_LVAL_PP(z_timezone_type)) {
af9dc8
 					case TIMELIB_ZONETYPE_OFFSET:
af9dc8
@@ -2541,7 +2538,6 @@ static int php_date_initialize_from_hash(php_date_obj **dateobj, HashTable *myht
af9dc8
 
af9dc8
 					case TIMELIB_ZONETYPE_ID: {
af9dc8
 						int ret;
af9dc8
-						convert_to_string(*z_timezone);
af9dc8
 
af9dc8
 						tzi = php_date_parse_tzfile(Z_STRVAL_PP(z_timezone), DATE_TIMEZONEDB TSRMLS_CC);
af9dc8
 
af9dc8
diff --git a/ext/date/tests/bug68942_2.phpt b/ext/date/tests/bug68942_2.phpt
af9dc8
new file mode 100644
af9dc8
index 0000000..5b02567
af9dc8
--- /dev/null
af9dc8
+++ b/ext/date/tests/bug68942_2.phpt
af9dc8
@@ -0,0 +1,9 @@
af9dc8
+--TEST--
af9dc8
+Bug #68942 (Use after free vulnerability in unserialize() with DateTime).
af9dc8
+--FILE--
af9dc8
+
af9dc8
+$data = unserialize('a:2:{i:0;O:8:"DateTime":3:{s:4:"date";s:26:"2000-01-01 00:00:00.000000";s:13:"timezone_type";a:2:{i:0;i:1;i:1;i:2;}s:8:"timezone";s:1:"A";}i:1;R:5;}');
af9dc8
+var_dump($data);
af9dc8
+?>
af9dc8
+--EXPECTF--
af9dc8
+Fatal error: Invalid serialization data for DateTime object in %s/bug68942_2.php on line %d
af9dc8
-- 
af9dc8
2.1.4
af9dc8