Skip to content

Commit 78389b2

Browse files
committed
Merge branch 'PHP-5.5' into PHP-5.6
* PHP-5.5: Fix bug #68942 (Use after free vulnerability in unserialize() with DateTimeZone) Port for for bug #68552 Fix bug #68942 (Use after free vulnerability in unserialize() with DateTimeZone) - BFN
2 parents f6e9ed7 + cf7d8ea commit 78389b2

File tree

5 files changed

+37
-15
lines changed

5 files changed

+37
-15
lines changed

NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,18 @@
3232
(Danack at basereality dot com)
3333
. Fixed bug #68925 (Mitigation for CVE-2015-0235 – GHOST: glibc gethostbyname
3434
buffer overflow). (Stas)
35+
. Fixed bug #68942 (Use after free vulnerability in unserialize() with
36+
DateTimeZone). (Stas)
3537
. Fixed Bug #67988 (htmlspecialchars() does not respect default_charset
3638
specified by ini_set) (Yasuo)
3739

3840
- Dba:
3941
. Fixed bug #68711 (useless comparisons). (bugreports at internot dot info)
4042

43+
- Enchant:
44+
. Fixed bug #6855 (heap buffer overflow in enchant_broker_request_dict()).
45+
(Antony)
46+
4147
- JSON:
4248
. Fixed bug #50224 (json_encode() does not always encode a float as a float)
4349
by adding JSON_PRESERVE_ZERO_FRACTION. (Juan Basso)

ext/date/php_date.c

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

2810-
if (zend_hash_find(myht, "date", 5, (void**) &z_date) == SUCCESS) {
2811-
convert_to_string(*z_date);
2812-
if (zend_hash_find(myht, "timezone_type", 14, (void**) &z_timezone_type) == SUCCESS) {
2813-
convert_to_long(*z_timezone_type);
2814-
if (zend_hash_find(myht, "timezone", 9, (void**) &z_timezone) == SUCCESS) {
2815-
convert_to_string(*z_timezone);
2810+
if (zend_hash_find(myht, "date", 5, (void**) &z_date) == SUCCESS && Z_TYPE_PP(z_date) == IS_STRING) {
2811+
if (zend_hash_find(myht, "timezone_type", 14, (void**) &z_timezone_type) == SUCCESS && Z_TYPE_PP(z_timezone_type) == IS_LONG) {
2812+
if (zend_hash_find(myht, "timezone", 9, (void**) &z_timezone) == SUCCESS && Z_TYPE_PP(z_timezone) == IS_STRING) {
28162813

28172814
switch (Z_LVAL_PP(z_timezone_type)) {
28182815
case TIMELIB_ZONETYPE_OFFSET:
@@ -2827,7 +2824,6 @@ static int php_date_initialize_from_hash(php_date_obj **dateobj, HashTable *myht
28272824

28282825
case TIMELIB_ZONETYPE_ID: {
28292826
int ret;
2830-
convert_to_string(*z_timezone);
28312827

28322828
tzi = php_date_parse_tzfile(Z_STRVAL_PP(z_timezone), DATE_TIMEZONEDB TSRMLS_CC);
28332829

@@ -3744,9 +3740,8 @@ static int php_date_timezone_initialize_from_hash(zval **return_value, php_timez
37443740
zval **z_timezone = NULL;
37453741
zval **z_timezone_type = NULL;
37463742

3747-
if (zend_hash_find(myht, "timezone_type", 14, (void**) &z_timezone_type) == SUCCESS) {
3743+
if (zend_hash_find(myht, "timezone_type", 14, (void**) &z_timezone_type) == SUCCESS && Z_TYPE_PP(z_timezone_type) == IS_LONG) {
37483744
if (zend_hash_find(myht, "timezone", 9, (void**) &z_timezone) == SUCCESS) {
3749-
convert_to_long(*z_timezone_type);
37503745
if (SUCCESS == timezone_initialize(*tzobj, Z_STRVAL_PP(z_timezone) TSRMLS_CC)) {
37513746
return SUCCESS;
37523747
}
@@ -3771,7 +3766,9 @@ PHP_METHOD(DateTimeZone, __set_state)
37713766

37723767
php_date_instantiate(date_ce_timezone, return_value TSRMLS_CC);
37733768
tzobj = (php_timezone_obj *) zend_object_store_get_object(return_value TSRMLS_CC);
3774-
php_date_timezone_initialize_from_hash(&return_value, &tzobj, myht TSRMLS_CC);
3769+
if(php_date_timezone_initialize_from_hash(&return_value, &tzobj, myht TSRMLS_CC) != SUCCESS) {
3770+
php_error_docref(NULL, E_ERROR, "Timezone initialization failed");
3771+
}
37753772
}
37763773
/* }}} */
37773774

@@ -3787,7 +3784,9 @@ PHP_METHOD(DateTimeZone, __wakeup)
37873784

37883785
myht = Z_OBJPROP_P(object);
37893786

3790-
php_date_timezone_initialize_from_hash(&return_value, &tzobj, myht TSRMLS_CC);
3787+
if(php_date_timezone_initialize_from_hash(&return_value, &tzobj, myht TSRMLS_CC) != SUCCESS) {
3788+
php_error_docref(NULL, E_ERROR, "Timezone initialization failed");
3789+
}
37913790
}
37923791
/* }}} */
37933792

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

ext/enchant/enchant.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,13 +550,12 @@ PHP_FUNCTION(enchant_broker_request_dict)
550550

551551
d = enchant_broker_request_dict(pbroker->pbroker, (const char *)tag);
552552
if (d) {
553+
pos = pbroker->dictcnt++;
553554
if (pbroker->dictcnt) {
554555
pbroker->dict = (enchant_dict **)erealloc(pbroker->dict, sizeof(enchant_dict *) * pbroker->dictcnt);
555-
pos = pbroker->dictcnt++;
556556
} else {
557557
pbroker->dict = (enchant_dict **)emalloc(sizeof(enchant_dict *));
558558
pos = 0;
559-
pbroker->dictcnt++;
560559
}
561560

562561
dict = pbroker->dict[pos] = (enchant_dict *)emalloc(sizeof(enchant_dict));
@@ -607,14 +606,14 @@ PHP_FUNCTION(enchant_broker_request_pwl_dict)
607606

608607
d = enchant_broker_request_pwl_dict(pbroker->pbroker, (const char *)pwl);
609608
if (d) {
609+
pos = pbroker->dictcnt++;
610610
if (pbroker->dictcnt) {
611-
pos = pbroker->dictcnt++;
612611
pbroker->dict = (enchant_dict **)erealloc(pbroker->dict, sizeof(enchant_dict *) * pbroker->dictcnt);
613612
} else {
614613
pbroker->dict = (enchant_dict **)emalloc(sizeof(enchant_dict *));
615614
pos = 0;
616-
pbroker->dictcnt++;
617615
}
616+
618617
dict = pbroker->dict[pos] = (enchant_dict *)emalloc(sizeof(enchant_dict));
619618
dict->id = pos;
620619
dict->pbroker = pbroker;

0 commit comments

Comments
 (0)