diff options
author | Craig Duncan <duncan3dc@php.net> | 2019-05-30 19:14:04 +0100 |
---|---|---|
committer | Craig Duncan <duncan3dc@php.net> | 2019-05-30 19:14:04 +0100 |
commit | a08b3b6d1924276662ea80d155c4f9e18147e1a0 (patch) | |
tree | 1c5a21714bfde1881334a8bffd34e4b8fbdf995e /ext/date | |
parent | ee565529138891e757727de230af9051caeda05d (diff) | |
parent | 370997fb5d2d6d2248064a6047d25d7794118470 (diff) | |
download | php-git-a08b3b6d1924276662ea80d155c4f9e18147e1a0.tar.gz |
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
Add a test for bug #65672
Ensure the internal properties cannot be overwritten
Diffstat (limited to 'ext/date')
-rw-r--r-- | ext/date/php_date.c | 37 | ||||
-rw-r--r-- | ext/date/tests/DatePeriod_properties2.phpt | 24 | ||||
-rw-r--r-- | ext/date/tests/bug65672.phpt | 44 |
3 files changed, 90 insertions, 15 deletions
diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 94f173be87..f7db8a26d7 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -5324,12 +5324,35 @@ PHP_METHOD(DatePeriod, __wakeup) } /* }}} */ +/* {{{ date_period_is_magic_property + * Common for date_period_read_property() and date_period_write_property() functions + */ +static int date_period_is_magic_property(zend_string *name) +{ + if (zend_string_equals_literal(name, "recurrences") + || zend_string_equals_literal(name, "include_start_date") + || zend_string_equals_literal(name, "start") + || zend_string_equals_literal(name, "current") + || zend_string_equals_literal(name, "end") + || zend_string_equals_literal(name, "interval") + ) { + return 1; + } + return 0; +} +/* }}} */ + /* {{{ date_period_read_property */ static zval *date_period_read_property(zval *object, zval *member, int type, void **cache_slot, zval *rv) { if (type != BP_VAR_IS && type != BP_VAR_R) { - zend_throw_error(NULL, "Retrieval of DatePeriod properties for modification is unsupported"); - return &EG(uninitialized_zval); + zend_string *name = zval_get_string(member); + if (date_period_is_magic_property(name)) { + zend_throw_error(NULL, "Retrieval of DatePeriod->%s for modification is unsupported", ZSTR_VAL(name)); + zend_string_release(name); + return &EG(uninitialized_zval); + } + zend_string_release(name); } Z_OBJPROP_P(object); /* build properties hash table */ @@ -5341,7 +5364,15 @@ static zval *date_period_read_property(zval *object, zval *member, int type, voi /* {{{ date_period_write_property */ static zval *date_period_write_property(zval *object, zval *member, zval *value, void **cache_slot) { - zend_throw_error(NULL, "Writing to DatePeriod properties is unsupported"); + zend_string *name = zval_get_string(member); + if (date_period_is_magic_property(name)) { + zend_throw_error(NULL, "Writing to DatePeriod->%s is unsupported", ZSTR_VAL(name)); + zend_string_release(name); + return value; + } + zend_string_release(name); + + std_object_handlers.write_property(object, member, value, cache_slot); return value; } /* }}} */ diff --git a/ext/date/tests/DatePeriod_properties2.phpt b/ext/date/tests/DatePeriod_properties2.phpt index 01858e68d4..044746c024 100644 --- a/ext/date/tests/DatePeriod_properties2.phpt +++ b/ext/date/tests/DatePeriod_properties2.phpt @@ -32,15 +32,15 @@ foreach ($properties as $property) { ?> --EXPECT-- -Writing to DatePeriod properties is unsupported -Retrieval of DatePeriod properties for modification is unsupported -Writing to DatePeriod properties is unsupported -Retrieval of DatePeriod properties for modification is unsupported -Writing to DatePeriod properties is unsupported -Retrieval of DatePeriod properties for modification is unsupported -Writing to DatePeriod properties is unsupported -Retrieval of DatePeriod properties for modification is unsupported -Writing to DatePeriod properties is unsupported -Retrieval of DatePeriod properties for modification is unsupported -Writing to DatePeriod properties is unsupported -Retrieval of DatePeriod properties for modification is unsupported +Writing to DatePeriod->recurrences is unsupported +Retrieval of DatePeriod->recurrences for modification is unsupported +Writing to DatePeriod->include_start_date is unsupported +Retrieval of DatePeriod->include_start_date for modification is unsupported +Writing to DatePeriod->start is unsupported +Retrieval of DatePeriod->start for modification is unsupported +Writing to DatePeriod->current is unsupported +Retrieval of DatePeriod->current for modification is unsupported +Writing to DatePeriod->end is unsupported +Retrieval of DatePeriod->end for modification is unsupported +Writing to DatePeriod->interval is unsupported +Retrieval of DatePeriod->interval for modification is unsupported diff --git a/ext/date/tests/bug65672.phpt b/ext/date/tests/bug65672.phpt new file mode 100644 index 0000000000..a84cff69ae --- /dev/null +++ b/ext/date/tests/bug65672.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test for bug #65672: Broken classes inherited from DatePeriod +--INI-- +date.timezone=UTC +--FILE-- +<?php + +$interval = new DateInterval('P1D'); +$period = new class(new DateTime, $interval, new DateTime) extends DatePeriod { + public $extra = "stuff"; +}; + +var_dump($period->extra); +$period->extra = "modified"; +var_dump($period->extra); + +# Ensure we can modify properties (retrieve for write) +$period->extra = []; +$period->extra[] = "array"; +var_dump($period->extra); + +var_dump(isset($period->dynamic1)); +$period->dynamic1 = "dynamic"; +var_dump($period->dynamic1); + +# Ensure we can modify properties (retrieve for write) +$period->dynamic2 = []; +$period->dynamic2[] = "array"; +var_dump($period->dynamic2); + +?> +--EXPECT-- +string(5) "stuff" +string(8) "modified" +array(1) { + [0]=> + string(5) "array" +} +bool(false) +string(7) "dynamic" +array(1) { + [0]=> + string(5) "array" +} |