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