com php-src: Ensure the internal properties cannot be overwritten: ext/date/php_date.c ext/date/tests/DatePeriod_propertie s2.phpt
| From: | Craig Duncan | Date: | Thu, 30 May 2019 17:55:36 +0000 |
| Subject: | com php-src: Ensure the internal properties cannot be overwritten: ext/date/php_date.c ext/date/tests/DatePeriod_propertie s2.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-106466@lists.php.net to get a copy of this message | ||
Commit: dc586bff36a8a7359942179b94b0f71e99c81d12
Author: Craig Duncan <git@duncanc.co.uk> Tue, 20 Feb 2018 21:11:03 +0000
Committer: Craig Duncan <duncan3dc@php.net> Thu, 30 May 2019 18:55:36 +0100
Parents: 5d67271db07b94321cd57c5679bc6ab02070bc11
Branches: PHP-7.2
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=dc586bff36a8a7359942179b94b0f71e99c81d12
Log:
Ensure the internal properties cannot be overwritten
Changed paths:
M ext/date/php_date.c
M ext/date/tests/DatePeriod_properties2.phpt
Diff:
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index f47ba5b..ba4ca6a 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -5310,12 +5310,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 */
@@ -5327,7 +5350,15 @@ static zval *date_period_read_property(zval *object, zval *member, int type,
voi
/* {{{ date_period_write_property */
static void 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;
+ }
+ zend_string_release(name);
+
+ std_object_handlers.write_property(object, member, value, cache_slot);
}
/* }}} */
diff --git a/ext/date/tests/DatePeriod_properties2.phpt b/ext/date/tests/DatePeriod_properties2.phpt
index 01858e6..044746c 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