Skip to content

Commit ea7604f

Browse files
committed
Merge branch 'PHP-5.6'
* PHP-5.6: More fixes for nodelist array access - testing for null property read - no zval copying if the type is already long - memory fix for master - use zend_long for offset Conflicts: ext/dom/php_dom.c
2 parents e33e4b2 + 37a685f commit ea7604f

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

ext/dom/php_dom.c

+7-14
Original file line numberDiff line numberDiff line change
@@ -1552,8 +1552,7 @@ zval *dom_nodelist_read_dimension(zval *object, zval *offset, int type, zval *rv
15521552
return NULL;
15531553
}
15541554

1555-
ZVAL_COPY(&offset_copy, offset);
1556-
convert_to_long(&offset_copy);
1555+
ZVAL_LONG(&offset_copy, zval_get_long(offset));
15571556

15581557
zend_call_method_with_1_params(object, Z_OBJCE_P(object), NULL, "item", rv, &offset_copy);
15591558

@@ -1562,21 +1561,15 @@ zval *dom_nodelist_read_dimension(zval *object, zval *offset, int type, zval *rv
15621561

15631562
int dom_nodelist_has_dimension(zval *object, zval *member, int check_empty TSRMLS_DC)
15641563
{
1565-
zval *length, offset_copy;
1566-
int ret;
1567-
1568-
ZVAL_COPY(&offset_copy, member);
1569-
convert_to_long(&offset_copy);
1564+
zend_long offset = zval_get_long(member);
15701565

1571-
if (Z_LVAL(offset_copy) < 0) {
1566+
if (offset < 0) {
15721567
return 0;
1573-
}
1574-
1575-
length = zend_read_property(Z_OBJCE_P(object), object, "length", sizeof("length") - 1, 0 TSRMLS_CC);
1576-
1577-
ret = Z_LVAL(offset_copy) < Z_LVAL_P(length);
1568+
} else {
1569+
zval *length = zend_read_property(Z_OBJCE_P(object), object, "length", sizeof("length") - 1, 0 TSRMLS_CC);
15781570

1579-
return ret;
1571+
return length && offset < Z_LVAL_P(length);
1572+
}
15801573
} /* }}} end dom_nodelist_has_dimension */
15811574

15821575
#endif /* HAVE_DOM */

ext/dom/tests/bug67949.phpt

+29-3
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,21 @@ var_dump($nodes[0]->textContent);
2222
var_dump($nodes[1]->textContent);
2323

2424
echo "testing offset not a long\n";
25-
$offset = 'test';
25+
$offset = ['test'];
26+
var_dump($offset);
27+
var_dump(isset($nodes[$offset]), $nodes[$offset]->textContent);
28+
var_dump($offset);
29+
30+
$something = 'test';
31+
$offset = &$something;
32+
33+
var_dump($offset);
34+
var_dump(isset($nodes[$offset]), $nodes[$offset]->textContent);
2635
var_dump($offset);
27-
var_dump($nodes[$offset]->textContent);
36+
37+
$offset = 'test';
2838
var_dump($offset);
29-
var_dump(isset($nodes[$offset]));
39+
var_dump(isset($nodes[$offset]), $nodes[$offset]->textContent);
3040
var_dump($offset);
3141

3242
echo "testing read_dimension with null offset\n";
@@ -49,13 +59,29 @@ string(4) "data"
4959
Notice: Trying to get property of non-object in %s on line %d
5060
NULL
5161
testing offset not a long
62+
array(1) {
63+
[0]=>
64+
string(4) "test"
65+
}
66+
67+
Notice: Trying to get property of non-object in %s on line %d
68+
bool(false)
69+
NULL
70+
array(1) {
71+
[0]=>
72+
string(4) "test"
73+
}
5274
string(4) "test"
75+
bool(true)
5376
string(4) "data"
5477
string(4) "test"
78+
string(4) "test"
5579
bool(true)
80+
string(4) "data"
5681
string(4) "test"
5782
testing read_dimension with null offset
5883
NULL
5984
testing attribute access
6085
string(4) "href"
6186
==DONE==
87+

0 commit comments

Comments
 (0)