summaryrefslogtreecommitdiff
path: root/ext/date
diff options
context:
space:
mode:
authorStanislav Malyshev <stas@php.net>2015-02-17 07:02:20 +0100
committerStanislav Malyshev <stas@php.net>2015-02-17 07:02:20 +0100
commit625ab10f990911fb474430ac7c83dfaea13346dd (patch)
tree31e1a468063c0f81b148dc6da07970831f7104fa /ext/date
parent85aab94d8105f2fa18650f59399dd5d8ddce3668 (diff)
downloadphp-git-625ab10f990911fb474430ac7c83dfaea13346dd.tar.gz
Fix bug #68942 (Use after free vulnerability in unserialize() with DateTimeZone)
Diffstat (limited to 'ext/date')
-rw-r--r--ext/date/php_date.c23
-rw-r--r--ext/date/tests/bug68942.phpt9
-rw-r--r--ext/date/tests/bug68942_2.phpt9
3 files changed, 30 insertions, 11 deletions
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index a89636c36c..819b1732f3 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -2720,15 +2720,11 @@ static int php_date_initialize_from_hash(php_date_obj **dateobj, HashTable *myht
php_timezone_obj *tzobj;
z_date = zend_hash_str_find(myht, "date", sizeof("data")-1);
- if (z_date) {
- convert_to_string(z_date);
+ if (z_date && Z_TYPE_P(z_date) == IS_STRING) {
z_timezone_type = zend_hash_str_find(myht, "timezone_type", sizeof("timezone_type")-1);
- if (z_timezone_type) {
- convert_to_long(z_timezone_type);
+ if (z_timezone_type && Z_TYPE_P(z_timezone_type) == IS_LONG) {
z_timezone = zend_hash_str_find(myht, "timezone", sizeof("timezone")-1);
- if (z_timezone) {
- convert_to_string(z_timezone);
-
+ if (z_timezone && Z_TYPE_P(z_timezone) == IS_STRING) {
switch (Z_LVAL_P(z_timezone_type)) {
case TIMELIB_ZONETYPE_OFFSET:
case TIMELIB_ZONETYPE_ABBR: {
@@ -2742,7 +2738,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_P(z_timezone), DATE_TIMEZONEDB);
@@ -3657,7 +3652,9 @@ static int php_date_timezone_initialize_from_hash(zval **return_value, php_timez
if ((z_timezone_type = zend_hash_str_find(myht, "timezone_type", sizeof("timezone_type")-1)) != NULL) {
if ((z_timezone = zend_hash_str_find(myht, "timezone", sizeof("timezone")-1)) != NULL) {
- convert_to_long(z_timezone_type);
+ if(Z_TYPE_P(z_timezone_type) != IS_LONG) {
+ return FAILURE;
+ }
if (SUCCESS == timezone_initialize(*tzobj, Z_STRVAL_P(z_timezone))) {
return SUCCESS;
}
@@ -3682,7 +3679,9 @@ PHP_METHOD(DateTimeZone, __set_state)
php_date_instantiate(date_ce_timezone, return_value);
tzobj = Z_PHPTIMEZONE_P(return_value);
- php_date_timezone_initialize_from_hash(&return_value, &tzobj, myht);
+ if(php_date_timezone_initialize_from_hash(&return_value, &tzobj, myht) != SUCCESS) {
+ php_error_docref(NULL, E_ERROR, "Timezone initialization failed");
+ }
}
/* }}} */
@@ -3698,7 +3697,9 @@ PHP_METHOD(DateTimeZone, __wakeup)
myht = Z_OBJPROP_P(object);
- php_date_timezone_initialize_from_hash(&return_value, &tzobj, myht);
+ if(php_date_timezone_initialize_from_hash(&return_value, &tzobj, myht) != 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
diff --git a/ext/date/tests/bug68942_2.phpt b/ext/date/tests/bug68942_2.phpt
new file mode 100644
index 0000000000..5b02567008
--- /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--
+<?php
+$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;}');
+var_dump($data);
+?>
+--EXPECTF--
+Fatal error: Invalid serialization data for DateTime object in %s/bug68942_2.php on line %d