Skip to content

Commit d2cde0b

Browse files
m.yakunincmb69
m.yakunin
authored andcommittedOct 18, 2019
Fix #70153 \DateInterval incorrectly unserialized
Added a separate macro for reading 'days' property, so that bool(false) is correctly converted to the proper internal representation.
1 parent e2a6bf4 commit d2cde0b

File tree

6 files changed

+35
-4
lines changed

6 files changed

+35
-4
lines changed
 

‎NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ PHP NEWS
66
. Fixed bug #78656 (Parse errors classified as highest log-level). (Erik
77
Lundin)
88

9+
- Date:
10+
. Fixed bug #70153 (\DateInterval incorrectly unserialized). (Maksim Iakunin)
11+
912
- Iconv:
1013
. Fixed bug #78642 (Wrong libiconv version displayed). (gedas at martynas,
1114
cmb).

‎ext/date/php_date.c

+15-1
Original file line numberDiff line numberDiff line change
@@ -4364,6 +4364,20 @@ static int php_date_interval_initialize_from_hash(zval **return_value, php_inter
43644364
} \
43654365
} while (0);
43664366

4367+
#define PHP_DATE_INTERVAL_READ_PROPERTY_DAYS(member) \
4368+
do { \
4369+
zval *z_arg = zend_hash_str_find(myht, "days", sizeof("days") - 1); \
4370+
if (z_arg && Z_TYPE_P(z_arg) == IS_FALSE) { \
4371+
(*intobj)->diff->member = -99999; \
4372+
} else if (z_arg && Z_TYPE_P(z_arg) <= IS_STRING) { \
4373+
zend_string *str = zval_get_string(z_arg); \
4374+
DATE_A64I((*intobj)->diff->member, ZSTR_VAL(str)); \
4375+
zend_string_release(str); \
4376+
} else { \
4377+
(*intobj)->diff->member = -1LL; \
4378+
} \
4379+
} while (0);
4380+
43674381
#define PHP_DATE_INTERVAL_READ_PROPERTY_DOUBLE(element, member, def) \
43684382
do { \
43694383
zval *z_arg = zend_hash_str_find(myht, element, sizeof(element) - 1); \
@@ -4392,7 +4406,7 @@ static int php_date_interval_initialize_from_hash(zval **return_value, php_inter
43924406
PHP_DATE_INTERVAL_READ_PROPERTY("weekday_behavior", weekday_behavior, int, -1)
43934407
PHP_DATE_INTERVAL_READ_PROPERTY("first_last_day_of", first_last_day_of, int, -1)
43944408
PHP_DATE_INTERVAL_READ_PROPERTY("invert", invert, int, 0);
4395-
PHP_DATE_INTERVAL_READ_PROPERTY_I64("days", days);
4409+
PHP_DATE_INTERVAL_READ_PROPERTY_DAYS(days);
43964410
PHP_DATE_INTERVAL_READ_PROPERTY("special_type", special.type, unsigned int, 0);
43974411
PHP_DATE_INTERVAL_READ_PROPERTY_I64("special_amount", special.amount);
43984412
PHP_DATE_INTERVAL_READ_PROPERTY("have_weekday_relative", have_weekday_relative, unsigned int, 0);

‎ext/date/tests/bug48678.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ DateInterval Object
3939
[weekday_behavior] => 0
4040
[first_last_day_of] => 0
4141
[invert] => 0
42-
[days] => 0
42+
[days] =>
4343
[special_type] => 0
4444
[special_amount] => 0
4545
[have_weekday_relative] => 0

‎ext/date/tests/bug53437.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ object(DatePeriod)#5 (6) {
136136
["invert"]=>
137137
int(0)
138138
["days"]=>
139-
int(0)
139+
bool(false)
140140
["special_type"]=>
141141
int(0)
142142
["special_amount"]=>

‎ext/date/tests/bug53437_var2.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ object(DateInterval)#2 (16) {
7171
["invert"]=>
7272
int(0)
7373
["days"]=>
74-
int(0)
74+
bool(false)
7575
["special_type"]=>
7676
int(0)
7777
["special_amount"]=>

‎ext/date/tests/bug70153.phpt

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug #70153 (\DateInterval incorrectly unserialized)
3+
--FILE--
4+
<?php
5+
$i1 = \DateInterval::createFromDateString('+1 month');
6+
$i2 = unserialize(serialize($i1));
7+
var_dump($i1->days, $i2->days);
8+
var_dump($i2->special_amount, $i2->special_amount);
9+
?>
10+
--EXPECT--
11+
bool(false)
12+
bool(false)
13+
int(0)
14+
int(0)

0 commit comments

Comments
 (0)