Skip to content

Commit d4295eb

Browse files
committed
Prevent recursion in ZF2 Parameters class
1 parent 7b9c1b6 commit d4295eb

File tree

2 files changed

+10
-22
lines changed

2 files changed

+10
-22
lines changed

ext/spl/spl_array.c

+5-12
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ static int spl_array_has_dimension_ex(int check_inherited, zval *object, zval *o
603603

604604
if (rv && zend_is_true(rv)) {
605605
zval_ptr_dtor(&rv);
606-
if (check_empty == 2) {
606+
if (check_empty != 1) {
607607
return 1;
608608
} else if (intern->fptr_offset_get) {
609609
value = spl_array_read_dimension_ex(1, object, offset, BP_VAR_R TSRMLS_CC);
@@ -629,6 +629,7 @@ static int spl_array_has_dimension_ex(int check_inherited, zval *object, zval *o
629629
return 0;
630630
}
631631
break;
632+
632633
case IS_DOUBLE:
633634
case IS_RESOURCE:
634635
case IS_BOOL:
@@ -646,28 +647,20 @@ static int spl_array_has_dimension_ex(int check_inherited, zval *object, zval *o
646647
return 0;
647648
}
648649
break;
650+
649651
default:
650652
zend_error(E_WARNING, "Illegal offset type");
651653
return 0;
652654
}
653655

654-
if (check_inherited && intern->fptr_offset_get) {
656+
if (check_empty && check_inherited && intern->fptr_offset_get) {
655657
value = spl_array_read_dimension_ex(1, object, offset, BP_VAR_R TSRMLS_CC);
656658
} else {
657659
value = *tmp;
658660
}
659661
}
660662

661-
switch (check_empty) {
662-
case 0:
663-
return Z_TYPE_P(value) != IS_NULL;
664-
case 2:
665-
return 1;
666-
case 1:
667-
return zend_is_true(value);
668-
}
669-
670-
return 0;
663+
return check_empty ? zend_is_true(value) : Z_TYPE_P(value) != IS_NULL;
671664
} /* }}} */
672665

673666
static int spl_array_has_dimension(zval *object, zval *offset, int check_empty TSRMLS_DC) /* {{{ */

ext/spl/tests/bug66834.phpt

+5-10
Original file line numberDiff line numberDiff line change
@@ -75,30 +75,27 @@ var_dump($object->offsetexists('qux'), isset($object['qux']), empty($object['qux
7575
echo "==== class with offsetGet() and offsetSet() ====\n";
7676
$object = new ArrayObjectGetSet;
7777
$object['foo'] = 42;
78-
var_dump($object->offsetExists('foo'), $object->offsetExists('sbb'), isset($object['foo']), isset($object['sbb']));
78+
var_dump($object->offsetExists('foo'), $object->offsetExists('sbb'), isset($object['foo']), isset($object['sbb']), empty($object['sbb']));
7979

8080
?>
8181
--EXPECTF--
8282
==== class with offsetExists() and offsetGet() ====
8383
string(37) "Called: ArrayObjectBoth::offsetExists"
8484
string(37) "Called: ArrayObjectBoth::offsetExists"
85-
string(34) "Called: ArrayObjectBoth::offsetGet"
8685
string(37) "Called: ArrayObjectBoth::offsetExists"
8786
string(34) "Called: ArrayObjectBoth::offsetGet"
8887
bool(true)
8988
bool(true)
9089
bool(true)
9190
string(37) "Called: ArrayObjectBoth::offsetExists"
9291
string(37) "Called: ArrayObjectBoth::offsetExists"
93-
string(34) "Called: ArrayObjectBoth::offsetGet"
9492
string(37) "Called: ArrayObjectBoth::offsetExists"
9593
string(34) "Called: ArrayObjectBoth::offsetGet"
9694
bool(true)
97-
bool(false)
95+
bool(true)
9896
bool(true)
9997
string(37) "Called: ArrayObjectBoth::offsetExists"
10098
string(37) "Called: ArrayObjectBoth::offsetExists"
101-
string(34) "Called: ArrayObjectBoth::offsetGet"
10299
string(37) "Called: ArrayObjectBoth::offsetExists"
103100
string(34) "Called: ArrayObjectBoth::offsetGet"
104101
bool(true)
@@ -121,7 +118,7 @@ string(39) "Called: ArrayObjectExists::offsetExists"
121118
string(39) "Called: ArrayObjectExists::offsetExists"
122119
string(39) "Called: ArrayObjectExists::offsetExists"
123120
bool(true)
124-
bool(false)
121+
bool(true)
125122
bool(true)
126123
string(39) "Called: ArrayObjectExists::offsetExists"
127124
string(39) "Called: ArrayObjectExists::offsetExists"
@@ -137,17 +134,14 @@ bool(false)
137134
bool(true)
138135
==== class with offsetGet() ====
139136
string(33) "Called: ArrayObjectGet::offsetGet"
140-
string(33) "Called: ArrayObjectGet::offsetGet"
141137
bool(true)
142138
bool(true)
143139
bool(true)
144140
string(33) "Called: ArrayObjectGet::offsetGet"
145-
string(33) "Called: ArrayObjectGet::offsetGet"
146141
bool(true)
147142
bool(false)
148143
bool(true)
149144
string(33) "Called: ArrayObjectGet::offsetGet"
150-
string(33) "Called: ArrayObjectGet::offsetGet"
151145
bool(true)
152146
bool(true)
153147
bool(false)
@@ -160,4 +154,5 @@ Notice: Undefined index: foo in %s on line %d
160154
bool(false)
161155
bool(true)
162156
bool(false)
163-
bool(false)
157+
bool(true)
158+
bool(true)

0 commit comments

Comments
 (0)