Skip to content

Commit 671fc2e

Browse files
committed
Merge branch 'pull-request/3233' into PHP-7.2
* pull-request/3233: Fix #76300 - Dont attempt to change visibility of a parent private
2 parents 5fbb098 + 2dca867 commit 671fc2e

File tree

3 files changed

+61
-30
lines changed

3 files changed

+61
-30
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Bug #76300: Unserialize of extended protected member broken
3+
--FILE--
4+
<?php
5+
class Base {
6+
private $id;
7+
public function __construct($id)
8+
{
9+
$this->id = $id;
10+
}
11+
}
12+
class Derived extends Base {
13+
protected $id;
14+
public function __construct($id)
15+
{
16+
parent::__construct($id + 20);
17+
$this->id = $id;
18+
}
19+
}
20+
$a = new Derived(44);
21+
$s = serialize($a);
22+
$u = unserialize($s);
23+
print_r($u);
24+
--EXPECT--
25+
Derived Object
26+
(
27+
[id:protected] => 44
28+
[id:Base:private] => 64
29+
)

ext/standard/var_unserializer.c

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ static zend_always_inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTab
429429

430430
unmangled = zend_string_init(unmangled_prop, unmangled_prop_len, 0);
431431
if (Z_TYPE_P(rval) == IS_OBJECT
432+
&& (unmangled_class == NULL || !strcmp(unmangled_class, "*") || !strcasecmp(unmangled_class, ZSTR_VAL(Z_OBJCE_P(rval)->name)))
432433
&& ((existing_propinfo = zend_hash_find_ptr(&Z_OBJCE_P(rval)->properties_info, unmangled)) != NULL)
433434
&& (existing_propinfo->flags & ZEND_ACC_PPP_MASK)) {
434435
if (existing_propinfo->flags & ZEND_ACC_PROTECTED) {
@@ -644,7 +645,7 @@ static int php_var_unserialize_internal(UNSERIALIZE_PARAMETER)
644645
start = cursor;
645646

646647

647-
#line 648 "ext/standard/var_unserializer.c"
648+
#line 649 "ext/standard/var_unserializer.c"
648649
{
649650
YYCTYPE yych;
650651
static const unsigned char yybm[] = {
@@ -702,9 +703,9 @@ static int php_var_unserialize_internal(UNSERIALIZE_PARAMETER)
702703
yy2:
703704
++YYCURSOR;
704705
yy3:
705-
#line 1035 "ext/standard/var_unserializer.re"
706+
#line 1036 "ext/standard/var_unserializer.re"
706707
{ return 0; }
707-
#line 708 "ext/standard/var_unserializer.c"
708+
#line 709 "ext/standard/var_unserializer.c"
708709
yy4:
709710
yych = *(YYMARKER = ++YYCURSOR);
710711
if (yych == ':') goto yy17;
@@ -751,13 +752,13 @@ static int php_var_unserialize_internal(UNSERIALIZE_PARAMETER)
751752
goto yy3;
752753
yy15:
753754
++YYCURSOR;
754-
#line 1029 "ext/standard/var_unserializer.re"
755+
#line 1030 "ext/standard/var_unserializer.re"
755756
{
756757
/* this is the case where we have less data than planned */
757758
php_error_docref(NULL, E_NOTICE, "Unexpected end of serialized data");
758759
return 0; /* not sure if it should be 0 or 1 here? */
759760
}
760-
#line 761 "ext/standard/var_unserializer.c"
761+
#line 762 "ext/standard/var_unserializer.c"
761762
yy17:
762763
yych = *++YYCURSOR;
763764
if (yybm[0+yych] & 128) {
@@ -768,13 +769,13 @@ static int php_var_unserialize_internal(UNSERIALIZE_PARAMETER)
768769
goto yy3;
769770
yy19:
770771
++YYCURSOR;
771-
#line 701 "ext/standard/var_unserializer.re"
772+
#line 702 "ext/standard/var_unserializer.re"
772773
{
773774
*p = YYCURSOR;
774775
ZVAL_NULL(rval);
775776
return 1;
776777
}
777-
#line 778 "ext/standard/var_unserializer.c"
778+
#line 779 "ext/standard/var_unserializer.c"
778779
yy21:
779780
yych = *++YYCURSOR;
780781
if (yych <= '/') goto yy18;
@@ -973,7 +974,7 @@ static int php_var_unserialize_internal(UNSERIALIZE_PARAMETER)
973974
goto yy18;
974975
yy56:
975976
++YYCURSOR;
976-
#line 652 "ext/standard/var_unserializer.re"
977+
#line 653 "ext/standard/var_unserializer.re"
977978
{
978979
zend_long id;
979980

@@ -998,7 +999,7 @@ static int php_var_unserialize_internal(UNSERIALIZE_PARAMETER)
998999

9991000
return 1;
10001001
}
1001-
#line 1002 "ext/standard/var_unserializer.c"
1002+
#line 1003 "ext/standard/var_unserializer.c"
10021003
yy58:
10031004
yych = *++YYCURSOR;
10041005
if (yych == '"') goto yy77;
@@ -1009,13 +1010,13 @@ static int php_var_unserialize_internal(UNSERIALIZE_PARAMETER)
10091010
goto yy18;
10101011
yy60:
10111012
++YYCURSOR;
1012-
#line 707 "ext/standard/var_unserializer.re"
1013+
#line 708 "ext/standard/var_unserializer.re"
10131014
{
10141015
*p = YYCURSOR;
10151016
ZVAL_BOOL(rval, parse_iv(start + 2));
10161017
return 1;
10171018
}
1018-
#line 1019 "ext/standard/var_unserializer.c"
1019+
#line 1020 "ext/standard/var_unserializer.c"
10191020
yy62:
10201021
++YYCURSOR;
10211022
if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
@@ -1035,7 +1036,7 @@ static int php_var_unserialize_internal(UNSERIALIZE_PARAMETER)
10351036
}
10361037
yy64:
10371038
++YYCURSOR;
1038-
#line 755 "ext/standard/var_unserializer.re"
1039+
#line 756 "ext/standard/var_unserializer.re"
10391040
{
10401041
#if SIZEOF_ZEND_LONG == 4
10411042
use_double:
@@ -1044,7 +1045,7 @@ static int php_var_unserialize_internal(UNSERIALIZE_PARAMETER)
10441045
ZVAL_DOUBLE(rval, zend_strtod((const char *)start + 2, NULL));
10451046
return 1;
10461047
}
1047-
#line 1048 "ext/standard/var_unserializer.c"
1048+
#line 1049 "ext/standard/var_unserializer.c"
10481049
yy66:
10491050
yych = *++YYCURSOR;
10501051
if (yych <= ',') {
@@ -1066,7 +1067,7 @@ static int php_var_unserialize_internal(UNSERIALIZE_PARAMETER)
10661067
goto yy18;
10671068
yy69:
10681069
++YYCURSOR;
1069-
#line 713 "ext/standard/var_unserializer.re"
1070+
#line 714 "ext/standard/var_unserializer.re"
10701071
{
10711072
#if SIZEOF_ZEND_LONG == 4
10721073
int digits = YYCURSOR - start - 3;
@@ -1092,14 +1093,14 @@ static int php_var_unserialize_internal(UNSERIALIZE_PARAMETER)
10921093
ZVAL_LONG(rval, parse_iv(start + 2));
10931094
return 1;
10941095
}
1095-
#line 1096 "ext/standard/var_unserializer.c"
1096+
#line 1097 "ext/standard/var_unserializer.c"
10961097
yy71:
10971098
yych = *++YYCURSOR;
10981099
if (yych == '"') goto yy85;
10991100
goto yy18;
11001101
yy72:
11011102
++YYCURSOR;
1102-
#line 677 "ext/standard/var_unserializer.re"
1103+
#line 678 "ext/standard/var_unserializer.re"
11031104
{
11041105
zend_long id;
11051106

@@ -1123,14 +1124,14 @@ static int php_var_unserialize_internal(UNSERIALIZE_PARAMETER)
11231124

11241125
return 1;
11251126
}
1126-
#line 1127 "ext/standard/var_unserializer.c"
1127+
#line 1128 "ext/standard/var_unserializer.c"
11271128
yy74:
11281129
yych = *++YYCURSOR;
11291130
if (yych == '"') goto yy87;
11301131
goto yy18;
11311132
yy75:
11321133
++YYCURSOR;
1133-
#line 877 "ext/standard/var_unserializer.re"
1134+
#line 878 "ext/standard/var_unserializer.re"
11341135
{
11351136
size_t len, len2, len3, maxlen;
11361137
zend_long elements;
@@ -1282,10 +1283,10 @@ static int php_var_unserialize_internal(UNSERIALIZE_PARAMETER)
12821283

12831284
return object_common2(UNSERIALIZE_PASSTHRU, elements);
12841285
}
1285-
#line 1286 "ext/standard/var_unserializer.c"
1286+
#line 1287 "ext/standard/var_unserializer.c"
12861287
yy77:
12871288
++YYCURSOR;
1288-
#line 802 "ext/standard/var_unserializer.re"
1289+
#line 803 "ext/standard/var_unserializer.re"
12891290
{
12901291
size_t len, maxlen;
12911292
zend_string *str;
@@ -1319,10 +1320,10 @@ static int php_var_unserialize_internal(UNSERIALIZE_PARAMETER)
13191320
ZVAL_STR(rval, str);
13201321
return 1;
13211322
}
1322-
#line 1323 "ext/standard/var_unserializer.c"
1323+
#line 1324 "ext/standard/var_unserializer.c"
13231324
yy79:
13241325
++YYCURSOR;
1325-
#line 836 "ext/standard/var_unserializer.re"
1326+
#line 837 "ext/standard/var_unserializer.re"
13261327
{
13271328
zend_long elements = parse_iv(start + 2);
13281329
/* use iv() not uiv() in order to check data range */
@@ -1352,7 +1353,7 @@ static int php_var_unserialize_internal(UNSERIALIZE_PARAMETER)
13521353

13531354
return finish_nested_data(UNSERIALIZE_PASSTHRU);
13541355
}
1355-
#line 1356 "ext/standard/var_unserializer.c"
1356+
#line 1357 "ext/standard/var_unserializer.c"
13561357
yy81:
13571358
yych = *++YYCURSOR;
13581359
if (yych <= '/') goto yy18;
@@ -1371,7 +1372,7 @@ static int php_var_unserialize_internal(UNSERIALIZE_PARAMETER)
13711372
goto yy18;
13721373
yy85:
13731374
++YYCURSOR;
1374-
#line 866 "ext/standard/var_unserializer.re"
1375+
#line 867 "ext/standard/var_unserializer.re"
13751376
{
13761377
zend_long elements;
13771378
if (!var_hash) return 0;
@@ -1382,10 +1383,10 @@ static int php_var_unserialize_internal(UNSERIALIZE_PARAMETER)
13821383
}
13831384
return object_common2(UNSERIALIZE_PASSTHRU, elements);
13841385
}
1385-
#line 1386 "ext/standard/var_unserializer.c"
1386+
#line 1387 "ext/standard/var_unserializer.c"
13861387
yy87:
13871388
++YYCURSOR;
1388-
#line 764 "ext/standard/var_unserializer.re"
1389+
#line 765 "ext/standard/var_unserializer.re"
13891390
{
13901391
size_t len, maxlen;
13911392
char *str;
@@ -1423,10 +1424,10 @@ static int php_var_unserialize_internal(UNSERIALIZE_PARAMETER)
14231424
}
14241425
return 1;
14251426
}
1426-
#line 1427 "ext/standard/var_unserializer.c"
1427+
#line 1428 "ext/standard/var_unserializer.c"
14271428
yy89:
14281429
++YYCURSOR;
1429-
#line 739 "ext/standard/var_unserializer.re"
1430+
#line 740 "ext/standard/var_unserializer.re"
14301431
{
14311432
*p = YYCURSOR;
14321433

@@ -1442,9 +1443,9 @@ static int php_var_unserialize_internal(UNSERIALIZE_PARAMETER)
14421443

14431444
return 1;
14441445
}
1445-
#line 1446 "ext/standard/var_unserializer.c"
1446+
#line 1447 "ext/standard/var_unserializer.c"
14461447
}
1447-
#line 1037 "ext/standard/var_unserializer.re"
1448+
#line 1038 "ext/standard/var_unserializer.re"
14481449

14491450

14501451
return 0;

ext/standard/var_unserializer.re

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ string_key:
433433

434434
unmangled = zend_string_init(unmangled_prop, unmangled_prop_len, 0);
435435
if (Z_TYPE_P(rval) == IS_OBJECT
436+
&& (unmangled_class == NULL || !strcmp(unmangled_class, "*") || !strcasecmp(unmangled_class, ZSTR_VAL(Z_OBJCE_P(rval)->name)))
436437
&& ((existing_propinfo = zend_hash_find_ptr(&Z_OBJCE_P(rval)->properties_info, unmangled)) != NULL)
437438
&& (existing_propinfo->flags & ZEND_ACC_PPP_MASK)) {
438439
if (existing_propinfo->flags & ZEND_ACC_PROTECTED) {

0 commit comments

Comments
 (0)