Skip to content

Commit 7b18981

Browse files
committed
Fix bug #68942 (Use after free vulnerability in unserialize() with DateTimeZone)
Conflicts: ext/date/php_date.c
1 parent 82d347a commit 7b18981

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

ext/date/php_date.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2575,12 +2575,9 @@ static int php_date_initialize_from_hash(php_date_obj **dateobj, HashTable *myht
25752575
timelib_tzinfo *tzi;
25762576
php_timezone_obj *tzobj;
25772577

2578-
if (zend_hash_find(myht, "date", 5, (void**) &z_date) == SUCCESS) {
2579-
convert_to_string(*z_date);
2580-
if (zend_hash_find(myht, "timezone_type", 14, (void**) &z_timezone_type) == SUCCESS) {
2581-
convert_to_long(*z_timezone_type);
2582-
if (zend_hash_find(myht, "timezone", 9, (void**) &z_timezone) == SUCCESS) {
2583-
convert_to_string(*z_timezone);
2578+
if (zend_hash_find(myht, "date", 5, (void**) &z_date) == SUCCESS && Z_TYPE_PP(z_date) == IS_STRING) {
2579+
if (zend_hash_find(myht, "timezone_type", 14, (void**) &z_timezone_type) == SUCCESS && Z_TYPE_PP(z_timezone_type) == IS_LONG) {
2580+
if (zend_hash_find(myht, "timezone", 9, (void**) &z_timezone) == SUCCESS && Z_TYPE_PP(z_timezone) == IS_STRING) {
25842581

25852582
switch (Z_LVAL_PP(z_timezone_type)) {
25862583
case TIMELIB_ZONETYPE_OFFSET:
@@ -2595,7 +2592,6 @@ static int php_date_initialize_from_hash(php_date_obj **dateobj, HashTable *myht
25952592

25962593
case TIMELIB_ZONETYPE_ID: {
25972594
int ret;
2598-
convert_to_string(*z_timezone);
25992595

26002596
tzi = php_date_parse_tzfile(Z_STRVAL_PP(z_timezone), DATE_TIMEZONEDB TSRMLS_CC);
26012597

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)