summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStanislav Malyshev <stas@php.net>2015-02-17 06:53:27 +0100
committerJulien Pauli <jpauli@php.net>2015-02-18 11:32:21 +0100
commitc377f1a715476934133f3254d1e0d4bf3743e2d2 (patch)
treeda0dd6380917bc96d49d6cf17338c9c327db0a77
parent68ca18215bfc551ee04f47534b56c65999e7ba42 (diff)
downloadphp-git-c377f1a715476934133f3254d1e0d4bf3743e2d2.tar.gz
Fix bug #68942 (Use after free vulnerability in unserialize() with DateTimeZone)
-rw-r--r--ext/date/php_date.c11
-rw-r--r--ext/date/tests/bug68942.phpt9
2 files changed, 16 insertions, 4 deletions
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index dab29d21f4..909377ba1f 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -3712,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;
}
@@ -3739,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");
+ }
}
/* }}} */
@@ -3755,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 0000000000..595cd9fa92
--- /dev/null
+++ b/ext/date/tests/bug68942.phpt
@@ -0,0 +1,9 @@
+--TEST--
+Bug #68942 (Use after free vulnerability in unserialize() with DateTimeZone).
+--FILE--
+<?php
+$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;}');
+var_dump($data);
+?>
+--EXPECTF--
+Fatal error: DateTimeZone::__wakeup(): Timezone initialization failed in %s/bug68942.php on line %d