Skip to content

Commit 29a4e71

Browse files
committed
Fix bug #68942 (Use after free vulnerability in unserialize() with DateTimeZone)
1 parent 9474205 commit 29a4e71

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ PHP NEWS
3939
(Danack at basereality dot com)
4040
. Fixed bug #68925 (Mitigation for CVE-2015-0235 – GHOST: glibc gethostbyname
4141
buffer overflow). (Stas)
42+
. Fixed bug #68942 (Use after free vulnerability in unserialize() with
43+
DateTimeZone). (Stas)
4244

4345
- Date:
4446
. Fixed bug #45081 (strtotime incorrectly interprets SGT time zone). (Derick)

ext/date/php_date.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2779,12 +2779,9 @@ static int php_date_initialize_from_hash(php_date_obj **dateobj, HashTable *myht
27792779
timelib_tzinfo *tzi;
27802780
php_timezone_obj *tzobj;
27812781

2782-
if (zend_hash_find(myht, "date", 5, (void**) &z_date) == SUCCESS) {
2783-
convert_to_string(*z_date);
2784-
if (zend_hash_find(myht, "timezone_type", 14, (void**) &z_timezone_type) == SUCCESS) {
2785-
convert_to_long(*z_timezone_type);
2786-
if (zend_hash_find(myht, "timezone", 9, (void**) &z_timezone) == SUCCESS) {
2787-
convert_to_string(*z_timezone);
2782+
if (zend_hash_find(myht, "date", 5, (void**) &z_date) == SUCCESS && Z_TYPE_PP(z_date) == IS_STRING) {
2783+
if (zend_hash_find(myht, "timezone_type", 14, (void**) &z_timezone_type) == SUCCESS && Z_TYPE_PP(z_timezone_type) == IS_LONG) {
2784+
if (zend_hash_find(myht, "timezone", 9, (void**) &z_timezone) == SUCCESS && Z_TYPE_PP(z_timezone) == IS_STRING) {
27882785

27892786
switch (Z_LVAL_PP(z_timezone_type)) {
27902787
case TIMELIB_ZONETYPE_OFFSET:
@@ -2799,7 +2796,6 @@ static int php_date_initialize_from_hash(php_date_obj **dateobj, HashTable *myht
27992796

28002797
case TIMELIB_ZONETYPE_ID: {
28012798
int ret;
2802-
convert_to_string(*z_timezone);
28032799

28042800
tzi = php_date_parse_tzfile(Z_STRVAL_PP(z_timezone), DATE_TIMEZONEDB TSRMLS_CC);
28052801

@@ -3716,9 +3712,8 @@ static int php_date_timezone_initialize_from_hash(zval **return_value, php_timez
37163712
zval **z_timezone = NULL;
37173713
zval **z_timezone_type = NULL;
37183714

3719-
if (zend_hash_find(myht, "timezone_type", 14, (void**) &z_timezone_type) == SUCCESS) {
3715+
if (zend_hash_find(myht, "timezone_type", 14, (void**) &z_timezone_type) == SUCCESS && Z_TYPE_PP(z_timezone_type) == IS_LONG) {
37203716
if (zend_hash_find(myht, "timezone", 9, (void**) &z_timezone) == SUCCESS) {
3721-
convert_to_long(*z_timezone_type);
37223717
if (SUCCESS == timezone_initialize(*tzobj, Z_STRVAL_PP(z_timezone) TSRMLS_CC)) {
37233718
return SUCCESS;
37243719
}
@@ -3743,7 +3738,9 @@ PHP_METHOD(DateTimeZone, __set_state)
37433738

37443739
php_date_instantiate(date_ce_timezone, return_value TSRMLS_CC);
37453740
tzobj = (php_timezone_obj *) zend_object_store_get_object(return_value TSRMLS_CC);
3746-
php_date_timezone_initialize_from_hash(&return_value, &tzobj, myht TSRMLS_CC);
3741+
if(php_date_timezone_initialize_from_hash(&return_value, &tzobj, myht TSRMLS_CC) != SUCCESS) {
3742+
php_error_docref(NULL, E_ERROR, "Timezone initialization failed");
3743+
}
37473744
}
37483745
/* }}} */
37493746

@@ -3759,7 +3756,9 @@ PHP_METHOD(DateTimeZone, __wakeup)
37593756

37603757
myht = Z_OBJPROP_P(object);
37613758

3762-
php_date_timezone_initialize_from_hash(&return_value, &tzobj, myht TSRMLS_CC);
3759+
if(php_date_timezone_initialize_from_hash(&return_value, &tzobj, myht TSRMLS_CC) != SUCCESS) {
3760+
php_error_docref(NULL, E_ERROR, "Timezone initialization failed");
3761+
}
37633762
}
37643763
/* }}} */
37653764

ext/date/tests/bug68942.phpt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--TEST--
2+
Bug #68942 (Use after free vulnerability in unserialize() with DateTimeZone).
3+
--FILE--
4+
<?php
5+
$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;}');
6+
var_dump($data);
7+
?>
8+
--EXPECTF--
9+
Fatal error: DateTimeZone::__wakeup(): Timezone initialization failed in %s/bug68942.php on line %d

ext/date/tests/bug68942_2.phpt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--TEST--
2+
Bug #68942 (Use after free vulnerability in unserialize() with DateTime).
3+
--FILE--
4+
<?php
5+
$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;}');
6+
var_dump($data);
7+
?>
8+
--EXPECTF--
9+
Fatal error: Invalid serialization data for DateTime object in %s/bug68942_2.php on line %d

0 commit comments

Comments
 (0)