summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2017-10-30 12:04:15 +0300
committerDmitry Stogov <dmitry@zend.com>2017-10-30 12:04:15 +0300
commit2065d51a18e3aa4e08ff806b5a8994fd4ad05746 (patch)
treed9b0b006b4ac9e2cca588280786933491e7ccc53
parent1f5c0fad21e84af36c833a935693a357636d2a2d (diff)
downloadphp-git-2065d51a18e3aa4e08ff806b5a8994fd4ad05746.tar.gz
Better fix for bug #75451 (Assertion fails while foreach on empty xpath query)
-rw-r--r--ext/dom/dom_iterators.c8
-rw-r--r--ext/dom/php_dom.h1
-rw-r--r--ext/dom/xpath.c5
3 files changed, 9 insertions, 5 deletions
diff --git a/ext/dom/dom_iterators.c b/ext/dom/dom_iterators.c
index 02f1e3c472..27bd960c4a 100644
--- a/ext/dom/dom_iterators.c
+++ b/ext/dom/dom_iterators.c
@@ -197,8 +197,8 @@ static void php_dom_iterator_move_forward(zend_object_iterator *iter) /* {{{ */
objmap->nodetype != XML_NOTATION_NODE) {
if (objmap->nodetype == DOM_NODESET) {
nodeht = HASH_OF(&objmap->baseobj_zv);
- zend_hash_move_forward(nodeht);
- if ((entry = zend_hash_get_current_data(nodeht))) {
+ zend_hash_move_forward_ex(nodeht, &iterator->pos);
+ if ((entry = zend_hash_get_current_data_ex(nodeht, &iterator->pos))) {
zval_ptr_dtor(&iterator->curobj);
ZVAL_UNDEF(&iterator->curobj);
ZVAL_COPY(&iterator->curobj, entry);
@@ -281,8 +281,8 @@ zend_object_iterator *php_dom_get_iterator(zend_class_entry *ce, zval *object, i
objmap->nodetype != XML_NOTATION_NODE) {
if (objmap->nodetype == DOM_NODESET) {
nodeht = HASH_OF(&objmap->baseobj_zv);
- zend_hash_internal_pointer_reset(nodeht);
- if ((entry = zend_hash_get_current_data(nodeht))) {
+ zend_hash_internal_pointer_reset_ex(nodeht, &iterator->pos);
+ if ((entry = zend_hash_get_current_data_ex(nodeht, &iterator->pos))) {
ZVAL_COPY(&iterator->curobj, entry);
}
} else {
diff --git a/ext/dom/php_dom.h b/ext/dom/php_dom.h
index 30d143c351..8bcbcd8306 100644
--- a/ext/dom/php_dom.h
+++ b/ext/dom/php_dom.h
@@ -93,6 +93,7 @@ typedef struct _dom_nnodemap_object {
typedef struct {
zend_object_iterator intern;
zval curobj;
+ HashPosition pos;
} php_dom_iterator;
#include "dom_fe.h"
diff --git a/ext/dom/xpath.c b/ext/dom/xpath.c
index 31e4dc98b4..f0b908ccf3 100644
--- a/ext/dom/xpath.c
+++ b/ext/dom/xpath.c
@@ -432,8 +432,9 @@ static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
int i;
xmlNodeSetPtr nodesetp;
- array_init(&retval);
if (xpathobjp->type == XPATH_NODESET && NULL != (nodesetp = xpathobjp->nodesetval) && nodesetp->nodeNr) {
+
+ array_init(&retval);
for (i = 0; i < nodesetp->nodeNr; i++) {
xmlNodePtr node = nodesetp->nodeTab[i];
zval child;
@@ -459,6 +460,8 @@ static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
php_dom_create_object(node, &child, &intern->dom);
add_next_index_zval(&retval, &child);
}
+ } else {
+ ZVAL_EMPTY_ARRAY(&retval);
}
php_dom_create_interator(return_value, DOM_NODELIST);
nodeobj = Z_DOMOBJ_P(return_value);