Skip to content

Promote warnings to error in DOM ext #5418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/dom/attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ PHP_METHOD(DOMAttr, __construct)
name_valid = xmlValidateName((xmlChar *) name, 0);
if (name_valid != 0) {
php_dom_throw_error(INVALID_CHARACTER_ERR, 1);
RETURN_FALSE;
RETURN_THROWS();
}

nodep = xmlNewProp(NULL, (xmlChar *) name, (xmlChar *) value);

if (!nodep) {
php_dom_throw_error(INVALID_STATE_ERR, 1);
RETURN_FALSE;
RETURN_THROWS();
}

oldnode = dom_object_get_node(intern);
Expand Down
2 changes: 1 addition & 1 deletion ext/dom/cdatasection.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ PHP_METHOD(DOMCdataSection, __construct)

if (!nodep) {
php_dom_throw_error(INVALID_STATE_ERR, 1);
return;
RETURN_THROWS();
}

intern = Z_DOMOBJ_P(ZEND_THIS);
Expand Down
2 changes: 1 addition & 1 deletion ext/dom/comment.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ PHP_METHOD(DOMComment, __construct)

if (!nodep) {
php_dom_throw_error(INVALID_STATE_ERR, 1);
return;
RETURN_THROWS();
}

intern = Z_DOMOBJ_P(ZEND_THIS);
Expand Down
5 changes: 3 additions & 2 deletions ext/dom/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ int dom_document_encoding_read(dom_object *obj, zval *retval)
return SUCCESS;
}

int dom_document_encoding_write(dom_object *obj, zval *newval)
zend_result dom_document_encoding_write(dom_object *obj, zval *newval)
{
xmlDoc *docp = (xmlDocPtr) dom_object_get_node(obj);
zend_string *str;
Expand All @@ -161,7 +161,8 @@ int dom_document_encoding_write(dom_object *obj, zval *newval)
}
docp->encoding = xmlStrdup((const xmlChar *) ZSTR_VAL(str));
} else {
php_error_docref(NULL, E_WARNING, "Invalid Document Encoding");
zend_value_error("Invalid document encoding");
return FAILURE;
}

zend_string_release_ex(str, 0);
Expand Down
2 changes: 1 addition & 1 deletion ext/dom/documentfragment.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ PHP_METHOD(DOMDocumentFragment, __construct)

if (!nodep) {
php_dom_throw_error(INVALID_STATE_ERR, 1);
return;
RETURN_THROWS();
}

intern = Z_DOMOBJ_P(ZEND_THIS);
Expand Down
18 changes: 9 additions & 9 deletions ext/dom/domimplementation.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ PHP_METHOD(DOMImplementation, createDocumentType)
}

if (name_len == 0) {
php_error_docref(NULL, E_WARNING, "qualifiedName is required");
RETURN_FALSE;
zend_argument_value_error(1, "cannot be empty");
RETURN_THROWS();
}

if (publicid_len > 0) {
Expand Down Expand Up @@ -134,12 +134,12 @@ PHP_METHOD(DOMImplementation, createDocument)
if (node != NULL) {
DOM_GET_OBJ(doctype, node, xmlDtdPtr, doctobj);
if (doctype->type == XML_DOCUMENT_TYPE_NODE) {
php_error_docref(NULL, E_WARNING, "Invalid DocumentType object");
RETURN_FALSE;
zend_argument_value_error(3, "is an invalid DocumentType object");
RETURN_THROWS();
}
if (doctype->doc != NULL) {
php_dom_throw_error(WRONG_DOCUMENT_ERR, 1);
RETURN_FALSE;
RETURN_THROWS();
}
} else {
doctobj = NULL;
Expand All @@ -163,7 +163,7 @@ PHP_METHOD(DOMImplementation, createDocument)
xmlFree(localname);
}
php_dom_throw_error(errorcode, 1);
RETURN_FALSE;
RETURN_THROWS();
}

/* currently letting libxml2 set the version string */
Expand Down Expand Up @@ -195,9 +195,9 @@ PHP_METHOD(DOMImplementation, createDocument)
}
xmlFreeDoc(docp);
xmlFree(localname);
/* Need some type of error here */
php_error_docref(NULL, E_WARNING, "Unexpected Error");
RETURN_FALSE;
/* Need some better type of error here */
php_dom_throw_error(PHP_ERR, 1);
RETURN_THROWS();
}

nodep->nsDef = nsptr;
Expand Down
34 changes: 17 additions & 17 deletions ext/dom/element.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ PHP_METHOD(DOMElement, __construct)
name_valid = xmlValidateName((xmlChar *) name, 0);
if (name_valid != 0) {
php_dom_throw_error(INVALID_CHARACTER_ERR, 1);
return;
RETURN_THROWS();
}

/* Namespace logic is separate and only when uri passed in to insure no BC breakage */
Expand All @@ -71,7 +71,7 @@ PHP_METHOD(DOMElement, __construct)
xmlFreeNode(nodep);
}
php_dom_throw_error(errorcode, 1);
return;
RETURN_THROWS();
}
} else {
/* If you don't pass a namespace uri, then you can't set a prefix */
Expand All @@ -80,14 +80,14 @@ PHP_METHOD(DOMElement, __construct)
xmlFree(localname);
xmlFree(prefix);
php_dom_throw_error(NAMESPACE_ERR, 1);
return;
RETURN_THROWS();
}
nodep = xmlNewNode(NULL, (xmlChar *) name);
}

if (!nodep) {
php_dom_throw_error(INVALID_STATE_ERR, 1);
return;
RETURN_THROWS();
}

if (value_len > 0) {
Expand Down Expand Up @@ -255,14 +255,14 @@ PHP_METHOD(DOMElement, setAttribute)
}

if (name_len == 0) {
php_error_docref(NULL, E_WARNING, "Attribute Name is required");
RETURN_FALSE;
zend_argument_value_error(1, "cannot be empty");
RETURN_THROWS();
}

name_valid = xmlValidateName((xmlChar *) name, 0);
if (name_valid != 0) {
php_dom_throw_error(INVALID_CHARACTER_ERR, 1);
RETURN_FALSE;
RETURN_THROWS();
}

DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
Expand Down Expand Up @@ -294,8 +294,8 @@ PHP_METHOD(DOMElement, setAttribute)
attr = (xmlNodePtr)xmlSetProp(nodep, (xmlChar *) name, (xmlChar *)value);
}
if (!attr) {
php_error_docref(NULL, E_WARNING, "No such attribute '%s'", name);
RETURN_FALSE;
zend_argument_value_error(1, "must be a valid XML attribute");
RETURN_THROWS();
}

DOM_RET_OBJ(attr, &ret, intern);
Expand Down Expand Up @@ -424,8 +424,8 @@ PHP_METHOD(DOMElement, setAttributeNode)
DOM_GET_OBJ(attrp, node, xmlAttrPtr, attrobj);

if (attrp->type != XML_ATTRIBUTE_NODE) {
php_error_docref(NULL, E_WARNING, "Attribute node is required");
RETURN_FALSE;
zend_argument_value_error(1, "must have the node attribute");
RETURN_THROWS();
}

if (!(attrp->doc == NULL || attrp->doc == nodep->doc)) {
Expand Down Expand Up @@ -628,8 +628,8 @@ PHP_METHOD(DOMElement, setAttributeNS)
}

if (name_len == 0) {
php_error_docref(NULL, E_WARNING, "Attribute Name is required");
RETURN_FALSE;
zend_argument_value_error(2, "cannot be empty");
Copy link
Member

@kocsismate kocsismate Sep 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change removes the only false return value :)

RETURN_THROWS();
}

DOM_GET_OBJ(elemp, id, xmlNodePtr, intern);
Expand Down Expand Up @@ -873,10 +873,10 @@ PHP_METHOD(DOMElement, setAttributeNodeNS)

DOM_GET_OBJ(attrp, node, xmlAttrPtr, attrobj);

if (attrp->type != XML_ATTRIBUTE_NODE) {
php_error_docref(NULL, E_WARNING, "Attribute node is required");
RETURN_FALSE;
}
/* ZPP Guarantees that a DOMAttr class is given, as it is converted to a xmlAttr
* to pass to libxml (see http://www.xmlsoft.org/html/libxml-tree.html#xmlAttr)
* if it is not of type XML_ATTRIBUTE_NODE it indicates a bug somewhere */
ZEND_ASSERT(attrp->type == XML_ATTRIBUTE_NODE);

if (!(attrp->doc == NULL || attrp->doc == nodep->doc)) {
php_dom_throw_error(WRONG_DOCUMENT_ERR, dom_get_strict_error(intern->document));
Expand Down
4 changes: 2 additions & 2 deletions ext/dom/entityreference.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ PHP_METHOD(DOMEntityReference, __construct)
name_valid = xmlValidateName((xmlChar *) name, 0);
if (name_valid != 0) {
php_dom_throw_error(INVALID_CHARACTER_ERR, 1);
RETURN_FALSE;
RETURN_THROWS();
}

node = xmlNewReference(NULL, (xmlChar *) name);

if (!node) {
php_dom_throw_error(INVALID_STATE_ERR, 1);
RETURN_FALSE;
RETURN_THROWS();
}

intern = Z_DOMOBJ_P(ZEND_THIS);
Expand Down
58 changes: 28 additions & 30 deletions ext/dom/namednodemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,44 +146,42 @@ PHP_METHOD(DOMNamedNodeMap, item)
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
RETURN_THROWS();
}
if (index >= 0) {
if (ZEND_LONG_INT_OVFL(index)) {
php_error_docref(NULL, E_WARNING, "Invalid index");
RETURN_NULL();
}
if (index < 0 || ZEND_LONG_INT_OVFL(index)) {
zend_argument_value_error(1, "must be between 0 and %d", INT_MAX);
RETURN_THROWS();
}

intern = Z_DOMOBJ_P(id);
intern = Z_DOMOBJ_P(id);

objmap = (dom_nnodemap_object *)intern->ptr;
objmap = (dom_nnodemap_object *)intern->ptr;

if (objmap != NULL) {
if ((objmap->nodetype == XML_NOTATION_NODE) ||
objmap->nodetype == XML_ENTITY_NODE) {
if (objmap->ht) {
if (objmap->nodetype == XML_ENTITY_NODE) {
itemnode = php_dom_libxml_hash_iter(objmap->ht, index);
} else {
itemnode = php_dom_libxml_notation_iter(objmap->ht, index);
}
if (objmap != NULL) {
if ((objmap->nodetype == XML_NOTATION_NODE) ||
objmap->nodetype == XML_ENTITY_NODE) {
if (objmap->ht) {
if (objmap->nodetype == XML_ENTITY_NODE) {
itemnode = php_dom_libxml_hash_iter(objmap->ht, index);
} else {
itemnode = php_dom_libxml_notation_iter(objmap->ht, index);
}
} else {
nodep = dom_object_get_node(objmap->baseobj);
if (nodep) {
curnode = (xmlNodePtr)nodep->properties;
count = 0;
while (count < index && curnode != NULL) {
count++;
curnode = (xmlNodePtr)curnode->next;
}
itemnode = curnode;
}
} else {
nodep = dom_object_get_node(objmap->baseobj);
if (nodep) {
curnode = (xmlNodePtr)nodep->properties;
count = 0;
while (count < index && curnode != NULL) {
count++;
curnode = (xmlNodePtr)curnode->next;
}
itemnode = curnode;
}
}
}

if (itemnode) {
DOM_RET_OBJ(itemnode, &ret, objmap->baseobj);
return;
}
if (itemnode) {
DOM_RET_OBJ(itemnode, &ret, objmap->baseobj);
return;
}

RETVAL_NULL();
Expand Down
Loading