Skip to content

Commit 370997f

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2: Add a test for bug #65672 Ensure the internal properties cannot be overwritten
2 parents 61a38bb + 8b53c72 commit 370997f

File tree

3 files changed

+90
-15
lines changed

3 files changed

+90
-15
lines changed

ext/date/php_date.c

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5307,12 +5307,35 @@ PHP_METHOD(DatePeriod, __wakeup)
53075307
}
53085308
/* }}} */
53095309

5310+
/* {{{ date_period_is_magic_property
5311+
* Common for date_period_read_property() and date_period_write_property() functions
5312+
*/
5313+
static int date_period_is_magic_property(zend_string *name)
5314+
{
5315+
if (zend_string_equals_literal(name, "recurrences")
5316+
|| zend_string_equals_literal(name, "include_start_date")
5317+
|| zend_string_equals_literal(name, "start")
5318+
|| zend_string_equals_literal(name, "current")
5319+
|| zend_string_equals_literal(name, "end")
5320+
|| zend_string_equals_literal(name, "interval")
5321+
) {
5322+
return 1;
5323+
}
5324+
return 0;
5325+
}
5326+
/* }}} */
5327+
53105328
/* {{{ date_period_read_property */
53115329
static zval *date_period_read_property(zval *object, zval *member, int type, void **cache_slot, zval *rv)
53125330
{
53135331
if (type != BP_VAR_IS && type != BP_VAR_R) {
5314-
zend_throw_error(NULL, "Retrieval of DatePeriod properties for modification is unsupported");
5315-
return &EG(uninitialized_zval);
5332+
zend_string *name = zval_get_string(member);
5333+
if (date_period_is_magic_property(name)) {
5334+
zend_throw_error(NULL, "Retrieval of DatePeriod->%s for modification is unsupported", ZSTR_VAL(name));
5335+
zend_string_release(name);
5336+
return &EG(uninitialized_zval);
5337+
}
5338+
zend_string_release(name);
53165339
}
53175340

53185341
Z_OBJPROP_P(object); /* build properties hash table */
@@ -5324,7 +5347,15 @@ static zval *date_period_read_property(zval *object, zval *member, int type, voi
53245347
/* {{{ date_period_write_property */
53255348
static void date_period_write_property(zval *object, zval *member, zval *value, void **cache_slot)
53265349
{
5327-
zend_throw_error(NULL, "Writing to DatePeriod properties is unsupported");
5350+
zend_string *name = zval_get_string(member);
5351+
if (date_period_is_magic_property(name)) {
5352+
zend_throw_error(NULL, "Writing to DatePeriod->%s is unsupported", ZSTR_VAL(name));
5353+
zend_string_release(name);
5354+
return;
5355+
}
5356+
zend_string_release(name);
5357+
5358+
std_object_handlers.write_property(object, member, value, cache_slot);
53285359
}
53295360
/* }}} */
53305361

ext/date/tests/DatePeriod_properties2.phpt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ foreach ($properties as $property) {
3232

3333
?>
3434
--EXPECT--
35-
Writing to DatePeriod properties is unsupported
36-
Retrieval of DatePeriod properties for modification is unsupported
37-
Writing to DatePeriod properties is unsupported
38-
Retrieval of DatePeriod properties for modification is unsupported
39-
Writing to DatePeriod properties is unsupported
40-
Retrieval of DatePeriod properties for modification is unsupported
41-
Writing to DatePeriod properties is unsupported
42-
Retrieval of DatePeriod properties for modification is unsupported
43-
Writing to DatePeriod properties is unsupported
44-
Retrieval of DatePeriod properties for modification is unsupported
45-
Writing to DatePeriod properties is unsupported
46-
Retrieval of DatePeriod properties for modification is unsupported
35+
Writing to DatePeriod->recurrences is unsupported
36+
Retrieval of DatePeriod->recurrences for modification is unsupported
37+
Writing to DatePeriod->include_start_date is unsupported
38+
Retrieval of DatePeriod->include_start_date for modification is unsupported
39+
Writing to DatePeriod->start is unsupported
40+
Retrieval of DatePeriod->start for modification is unsupported
41+
Writing to DatePeriod->current is unsupported
42+
Retrieval of DatePeriod->current for modification is unsupported
43+
Writing to DatePeriod->end is unsupported
44+
Retrieval of DatePeriod->end for modification is unsupported
45+
Writing to DatePeriod->interval is unsupported
46+
Retrieval of DatePeriod->interval for modification is unsupported

ext/date/tests/bug65672.phpt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
--TEST--
2+
Test for bug #65672: Broken classes inherited from DatePeriod
3+
--INI--
4+
date.timezone=UTC
5+
--FILE--
6+
<?php
7+
8+
$interval = new DateInterval('P1D');
9+
$period = new class(new DateTime, $interval, new DateTime) extends DatePeriod {
10+
public $extra = "stuff";
11+
};
12+
13+
var_dump($period->extra);
14+
$period->extra = "modified";
15+
var_dump($period->extra);
16+
17+
# Ensure we can modify properties (retrieve for write)
18+
$period->extra = [];
19+
$period->extra[] = "array";
20+
var_dump($period->extra);
21+
22+
var_dump(isset($period->dynamic1));
23+
$period->dynamic1 = "dynamic";
24+
var_dump($period->dynamic1);
25+
26+
# Ensure we can modify properties (retrieve for write)
27+
$period->dynamic2 = [];
28+
$period->dynamic2[] = "array";
29+
var_dump($period->dynamic2);
30+
31+
?>
32+
--EXPECT--
33+
string(5) "stuff"
34+
string(8) "modified"
35+
array(1) {
36+
[0]=>
37+
string(5) "array"
38+
}
39+
bool(false)
40+
string(7) "dynamic"
41+
array(1) {
42+
[0]=>
43+
string(5) "array"
44+
}

0 commit comments

Comments
 (0)