Skip to content

Commit 6fa3716

Browse files
committed
Fixed bug #31098 (isset false positive)
1 parent 222e5f9 commit 6fa3716

File tree

4 files changed

+308
-127
lines changed

4 files changed

+308
-127
lines changed

Zend/tests/bug31098.phpt

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,44 @@ $a = 'a';
1414
var_dump(isset($a{'b'}));
1515
$a = '0';
1616
var_dump(isset($a{'b'}));
17+
18+
$simpleString = "Bogus String Text";
19+
echo isset($simpleString->wrong)?"bug\n":"ok\n";
20+
echo isset($simpleString["wrong"])?"bug\n":"ok\n";
21+
echo isset($simpleString[-1])?"bug\n":"ok\n";
22+
echo isset($simpleString[0])?"ok\n":"bug\n";
23+
echo isset($simpleString["0"])?"ok\n":"bug\n";
24+
echo isset($simpleString["16"])?"ok\n":"bug\n";
25+
echo isset($simpleString["17"])?"bug\n":"ok\n";
26+
echo isset($simpleString["wrong"][0])?"bug\n":"ok\n";
27+
echo $simpleString->wrong === null?"ok\n":"bug\n";
28+
echo $simpleString["wrong"] === null?"ok\n":"bug\n";
29+
echo $simpleString["0"] === "B"?"ok\n":"bug\n";
30+
$simpleString["wrong"] = "f";
31+
echo $simpleString["0"] === "B"?"ok\n":"bug\n";
1732
?>
1833
--EXPECTF--
1934
bool(false)
2035
bool(false)
2136
bool(false)
2237
bool(false)
23-
bool(true)
24-
bool(true)
38+
bool(false)
39+
bool(false)
40+
ok
41+
ok
42+
ok
43+
ok
44+
ok
45+
ok
46+
ok
47+
ok
48+
49+
Notice: Trying to get property of non-object in %sbug31098.php on line %d
50+
ok
51+
52+
Notice: Trying to get string index from a string in %sbug31098.php on line %d
53+
ok
54+
ok
2555

56+
Notice: Trying to get string index from a string in %sbug31098.php on line %d
57+
ok

Zend/zend_execute.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,28 @@ static void zend_fetch_dimension_address(temp_variable *result, zval **container
11901190
zend_error_noreturn(E_ERROR, "[] operator not supported for strings");
11911191
}
11921192

1193-
if (dim->type != IS_LONG) {
1193+
if (Z_TYPE_P(dim) == IS_STRING) {
1194+
char *strval;
1195+
long lval;
1196+
1197+
strval = Z_STRVAL_P(dim);
1198+
if (is_numeric_string(strval, Z_STRLEN_P(dim), &lval, NULL, 0) == IS_LONG) {
1199+
ZVAL_LONG(&tmp, lval);
1200+
dim = &tmp;
1201+
} else {
1202+
if (type != BP_VAR_IS && type != BP_VAR_UNSET) {
1203+
zend_error(E_NOTICE, "Trying to get string index from a string");
1204+
}
1205+
if (result) {
1206+
result->var.ptr_ptr = &EG(error_zval_ptr);
1207+
PZVAL_LOCK(*result->var.ptr_ptr);
1208+
if (type == BP_VAR_R || type == BP_VAR_IS) {
1209+
AI_USE_PTR(result->var);
1210+
}
1211+
}
1212+
return;
1213+
}
1214+
} else if (dim->type != IS_LONG) {
11941215
tmp = *dim;
11951216
zval_copy_ctor(&tmp);
11961217
convert_to_long(&tmp);

Zend/zend_vm_def.h

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3190,26 +3190,37 @@ ZEND_VM_HELPER_EX(zend_isset_isempty_dim_prop_obj_handler, VAR|UNUSED|CV, CONST|
31903190
} else {
31913191
result = Z_OBJ_HT_P(*container)->has_dimension(*container, offset, (opline->extended_value == ZEND_ISEMPTY) TSRMLS_CC);
31923192
}
3193-
} else if ((*container)->type == IS_STRING) { /* string offsets */
3194-
zval tmp_offset;
3195-
3196-
if (Z_TYPE_P(offset) != IS_LONG) {
3197-
tmp_offset = *offset;
3198-
zval_copy_ctor(&tmp_offset);
3199-
convert_to_long(&tmp_offset);
3200-
offset = &tmp_offset;
3193+
} else if ((*container)->type == IS_STRING && !prop_dim) { /* string offsets */
3194+
zval tmp;
3195+
3196+
if (Z_TYPE_P(offset) == IS_STRING) {
3197+
char *strval;
3198+
long lval;
3199+
3200+
strval = Z_STRVAL_P(offset);
3201+
if (is_numeric_string(strval, Z_STRLEN_P(offset), &lval, NULL, 0) == IS_LONG) {
3202+
ZVAL_LONG(&tmp, lval);
3203+
offset = &tmp;
3204+
}
3205+
} else if (offset->type != IS_LONG) {
3206+
tmp = *offset;
3207+
zval_copy_ctor(&tmp);
3208+
convert_to_long(&tmp);
3209+
offset = &tmp;
32013210
}
3202-
switch (opline->extended_value) {
3203-
case ZEND_ISSET:
3204-
if (offset->value.lval >= 0 && offset->value.lval < Z_STRLEN_PP(container)) {
3205-
result = 1;
3206-
}
3207-
break;
3208-
case ZEND_ISEMPTY:
3209-
if (offset->value.lval >= 0 && offset->value.lval < Z_STRLEN_PP(container) && Z_STRVAL_PP(container)[offset->value.lval] != '0') {
3210-
result = 1;
3211-
}
3212-
break;
3211+
if (offset->type == IS_LONG) {
3212+
switch (opline->extended_value) {
3213+
case ZEND_ISSET:
3214+
if (offset->value.lval >= 0 && offset->value.lval < Z_STRLEN_PP(container)) {
3215+
result = 1;
3216+
}
3217+
break;
3218+
case ZEND_ISEMPTY:
3219+
if (offset->value.lval >= 0 && offset->value.lval < Z_STRLEN_PP(container) && Z_STRVAL_PP(container)[offset->value.lval] != '0') {
3220+
result = 1;
3221+
}
3222+
break;
3223+
}
32133224
}
32143225
}
32153226
}

0 commit comments

Comments
 (0)