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

8bac60
From 29a4e710de6a73341da3d268343fdfc072ba682a Mon Sep 17 00:00:00 2001
8bac60
From: Stanislav Malyshev <stas@php.net>
8bac60
Date: Tue, 17 Feb 2015 06:53:27 +0100
8bac60
Subject: [PATCH] Fix bug #68942 (Use after free vulnerability in unserialize()
8bac60
 with DateTimeZone)
8bac60
8bac60
---
8bac60
 NEWS                           |  2 ++
8bac60
 ext/date/php_date.c            | 21 ++++++++++-----------
8bac60
 ext/date/tests/bug68942.phpt   |  9 +++++++++
8bac60
 ext/date/tests/bug68942_2.phpt |  9 +++++++++
8bac60
 4 files changed, 30 insertions(+), 11 deletions(-)
8bac60
 create mode 100644 ext/date/tests/bug68942.phpt
8bac60
 create mode 100644 ext/date/tests/bug68942_2.phpt
8bac60
8bac60
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
8bac60
index 58e23c0..909377b 100644
8bac60
--- a/ext/date/php_date.c
8bac60
+++ b/ext/date/php_date.c
8bac60
@@ -2779,12 +2779,9 @@ static int php_date_initialize_from_hash(php_date_obj **dateobj, HashTable *myht
8bac60
 	timelib_tzinfo   *tzi;
8bac60
 	php_timezone_obj *tzobj;
8bac60
 
8bac60
-	if (zend_hash_find(myht, "date", 5, (void**) &z_date) == SUCCESS) {
8bac60
-		convert_to_string(*z_date);
8bac60
-		if (zend_hash_find(myht, "timezone_type", 14, (void**) &z_timezone_type) == SUCCESS) {
8bac60
-			convert_to_long(*z_timezone_type);
8bac60
-			if (zend_hash_find(myht, "timezone", 9, (void**) &z_timezone) == SUCCESS) {
8bac60
-				convert_to_string(*z_timezone);
8bac60
+	if (zend_hash_find(myht, "date", 5, (void**) &z_date) == SUCCESS && Z_TYPE_PP(z_date) == IS_STRING) {
8bac60
+		if (zend_hash_find(myht, "timezone_type", 14, (void**) &z_timezone_type) == SUCCESS && Z_TYPE_PP(z_timezone_type) == IS_LONG) {
8bac60
+			if (zend_hash_find(myht, "timezone", 9, (void**) &z_timezone) == SUCCESS && Z_TYPE_PP(z_timezone) == IS_STRING) {
8bac60
 
8bac60
 				switch (Z_LVAL_PP(z_timezone_type)) {
8bac60
 					case TIMELIB_ZONETYPE_OFFSET:
8bac60
@@ -2799,7 +2796,6 @@ static int php_date_initialize_from_hash(php_date_obj **dateobj, HashTable *myht
8bac60
 
8bac60
 					case TIMELIB_ZONETYPE_ID: {
8bac60
 						int ret;
8bac60
-						convert_to_string(*z_timezone);
8bac60
 
8bac60
 						tzi = php_date_parse_tzfile(Z_STRVAL_PP(z_timezone), DATE_TIMEZONEDB TSRMLS_CC);
8bac60
 
8bac60
@@ -3716,9 +3712,8 @@ static int php_date_timezone_initialize_from_hash(zval **return_value, php_timez
8bac60
 	zval            **z_timezone = NULL;
8bac60
 	zval            **z_timezone_type = NULL;
8bac60
 
8bac60
-	if (zend_hash_find(myht, "timezone_type", 14, (void**) &z_timezone_type) == SUCCESS) {
8bac60
+	if (zend_hash_find(myht, "timezone_type", 14, (void**) &z_timezone_type) == SUCCESS && Z_TYPE_PP(z_timezone_type) == IS_LONG) {
8bac60
 		if (zend_hash_find(myht, "timezone", 9, (void**) &z_timezone) == SUCCESS) {
8bac60
-			convert_to_long(*z_timezone_type);
8bac60
 			if (SUCCESS == timezone_initialize(*tzobj, Z_STRVAL_PP(z_timezone) TSRMLS_CC)) {
8bac60
 				return SUCCESS;
8bac60
 			}
8bac60
@@ -3743,7 +3738,9 @@ PHP_METHOD(DateTimeZone, __set_state)
8bac60
 
8bac60
 	php_date_instantiate(date_ce_timezone, return_value TSRMLS_CC);
8bac60
 	tzobj = (php_timezone_obj *) zend_object_store_get_object(return_value TSRMLS_CC);
8bac60
-	php_date_timezone_initialize_from_hash(&return_value, &tzobj, myht TSRMLS_CC);
8bac60
+	if(php_date_timezone_initialize_from_hash(&return_value, &tzobj, myht TSRMLS_CC) != SUCCESS) {
8bac60
+		php_error_docref(NULL, E_ERROR, "Timezone initialization failed");
8bac60
+	}
8bac60
 }
8bac60
 /* }}} */
8bac60
 
8bac60
@@ -3759,7 +3756,9 @@ PHP_METHOD(DateTimeZone, __wakeup)
8bac60
 
8bac60
 	myht = Z_OBJPROP_P(object);
8bac60
 	
8bac60
-	php_date_timezone_initialize_from_hash(&return_value, &tzobj, myht TSRMLS_CC);
8bac60
+	if(php_date_timezone_initialize_from_hash(&return_value, &tzobj, myht TSRMLS_CC) != SUCCESS) {
8bac60
+		php_error_docref(NULL, E_ERROR, "Timezone initialization failed");
8bac60
+	}
8bac60
 }
8bac60
 /* }}} */
8bac60
 
8bac60
diff --git a/ext/date/tests/bug68942.phpt b/ext/date/tests/bug68942.phpt
8bac60
new file mode 100644
8bac60
index 0000000..595cd9f
8bac60
--- /dev/null
8bac60
+++ b/ext/date/tests/bug68942.phpt
8bac60
@@ -0,0 +1,9 @@
8bac60
+--TEST--
8bac60
+Bug #68942 (Use after free vulnerability in unserialize() with DateTimeZone).
8bac60
+--FILE--
8bac60
+
8bac60
+$data = unserialize('a:2:{i:0;O:12:"DateTimeZone":2:{s:13:"timezone_type";a:2:{i:0;i:1;i:1;i:2;}s:8:"timezone";s:1:"A";}i:1;R:4;}');
8bac60
+var_dump($data);
8bac60
+?>
8bac60
+--EXPECTF--
8bac60
+Fatal error: DateTimeZone::__wakeup(): Timezone initialization failed in %s/bug68942.php on line %d
8bac60
diff --git a/ext/date/tests/bug68942_2.phpt b/ext/date/tests/bug68942_2.phpt
8bac60
new file mode 100644
8bac60
index 0000000..5b02567
8bac60
--- /dev/null
8bac60
+++ b/ext/date/tests/bug68942_2.phpt
8bac60
@@ -0,0 +1,9 @@
8bac60
+--TEST--
8bac60
+Bug #68942 (Use after free vulnerability in unserialize() with DateTime).
8bac60
+--FILE--
8bac60
+
8bac60
+$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;}');
8bac60
+var_dump($data);
8bac60
+?>
8bac60
+--EXPECTF--
8bac60
+Fatal error: Invalid serialization data for DateTime object in %s/bug68942_2.php on line %d
8bac60
From 213725057e0625829615f90f76cbb0172f757a33 Mon Sep 17 00:00:00 2001
8bac60
From: Stanislav Malyshev <stas@php.net>
8bac60
Date: Tue, 17 Feb 2015 07:47:12 +0100
8bac60
Subject: [PATCH] fix TS build
8bac60
8bac60
---
8bac60
 ext/date/php_date.c | 4 ++--
8bac60
 1 file changed, 2 insertions(+), 2 deletions(-)
8bac60
8bac60
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
8bac60
index 909377b..720cdb6 100644
8bac60
--- a/ext/date/php_date.c
8bac60
+++ b/ext/date/php_date.c
8bac60
@@ -3739,7 +3739,7 @@ PHP_METHOD(DateTimeZone, __set_state)
8bac60
 	php_date_instantiate(date_ce_timezone, return_value TSRMLS_CC);
8bac60
 	tzobj = (php_timezone_obj *) zend_object_store_get_object(return_value TSRMLS_CC);
8bac60
 	if(php_date_timezone_initialize_from_hash(&return_value, &tzobj, myht TSRMLS_CC) != SUCCESS) {
8bac60
-		php_error_docref(NULL, E_ERROR, "Timezone initialization failed");
8bac60
+		php_error_docref(NULL TSRMLS_CC, E_ERROR, "Timezone initialization failed");
8bac60
 	}
8bac60
 }
8bac60
 /* }}} */
8bac60
@@ -3757,7 +3757,7 @@ PHP_METHOD(DateTimeZone, __wakeup)
8bac60
 	myht = Z_OBJPROP_P(object);
8bac60
 	
8bac60
 	if(php_date_timezone_initialize_from_hash(&return_value, &tzobj, myht TSRMLS_CC) != SUCCESS) {
8bac60
-		php_error_docref(NULL, E_ERROR, "Timezone initialization failed");
8bac60
+		php_error_docref(NULL TSRMLS_CC, E_ERROR, "Timezone initialization failed");
8bac60
 	}
8bac60
 }
8bac60
 /* }}} */
8bac60
From e441d71baae89bdc5dc6f75407b4a8f5e42b8fa9 Mon Sep 17 00:00:00 2001
8bac60
From: Taoguang Chen <chtg@users.noreply.github.com>
8bac60
Date: Fri, 27 Feb 2015 10:41:53 +0800
8bac60
Subject: [PATCH] fix bug#68942's patch
8bac60
8bac60
Fix type confusion bug in unserialize() with DateTimeZone. https://bugs.php.net/bug.php?id=68942
8bac60
---
8bac60
 ext/date/php_date.c | 2 +-
8bac60
 1 file changed, 1 insertion(+), 1 deletion(-)
8bac60
8bac60
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
8bac60
index 720cdb6..81f6ae4 100644
8bac60
--- a/ext/date/php_date.c
8bac60
+++ b/ext/date/php_date.c
8bac60
@@ -3713,7 +3713,7 @@ static int php_date_timezone_initialize_from_hash(zval **return_value, php_timez
8bac60
 	zval            **z_timezone_type = NULL;
8bac60
 
8bac60
 	if (zend_hash_find(myht, "timezone_type", 14, (void**) &z_timezone_type) == SUCCESS && Z_TYPE_PP(z_timezone_type) == IS_LONG) {
8bac60
-		if (zend_hash_find(myht, "timezone", 9, (void**) &z_timezone) == SUCCESS) {
8bac60
+		if (zend_hash_find(myht, "timezone", 9, (void**) &z_timezone) == SUCCESS && Z_TYPE_PP(z_timezone) == IS_STRING) {
8bac60
 			if (SUCCESS == timezone_initialize(*tzobj, Z_STRVAL_PP(z_timezone) TSRMLS_CC)) {
8bac60
 				return SUCCESS;
8bac60
 			}