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

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