Skip to content
Merged
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/documenttype.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ zend_result dom_documenttype_entities_read(dom_object *obj, zval *retval)
{
DOM_PROP_NODE(xmlDtdPtr, dtdptr, obj);

object_init_ex(retval, dom_get_dtd_namednodemap_ce(php_dom_follow_spec_intern(obj)));
object_init_ex(retval, dom_get_dtd_namednodemap_ce(instanceof_function(obj->std.ce, dom_modern_documenttype_class_entry)));

xmlHashTable *entityht = (xmlHashTable *) dtdptr->entities;

Expand All @@ -74,7 +74,7 @@ zend_result dom_documenttype_notations_read(dom_object *obj, zval *retval)
{
DOM_PROP_NODE(xmlDtdPtr, dtdptr, obj);

object_init_ex(retval, dom_get_dtd_namednodemap_ce(php_dom_follow_spec_intern(obj)));
object_init_ex(retval, dom_get_dtd_namednodemap_ce(instanceof_function(obj->std.ce, dom_modern_documenttype_class_entry)));

xmlHashTable *notationht = (xmlHashTable *) dtdptr->notations;

Expand Down
2 changes: 2 additions & 0 deletions ext/dom/dom_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ zend_result dom_entity_version_read(dom_object *obj, zval *retval);
zend_result dom_entity_reference_child_read(dom_object *obj, zval *retval);
zend_result dom_entity_reference_text_content_read(dom_object *obj, zval *retval);
zend_result dom_entity_reference_child_nodes_read(dom_object *obj, zval *retval);
zend_result dom_modern_entity_reference_child_nodes_read(dom_object *obj, zval *retval);

/* namednodemap properties */
zend_result dom_namednodemap_length_read(dom_object *obj, zval *retval);
Expand All @@ -122,6 +123,7 @@ zend_result dom_node_node_type_read(dom_object *obj, zval *retval);
zend_result dom_node_parent_node_read(dom_object *obj, zval *retval);
zend_result dom_node_parent_element_read(dom_object *obj, zval *retval);
zend_result dom_node_child_nodes_read(dom_object *obj, zval *retval);
zend_result dom_modern_node_child_nodes_read(dom_object *obj, zval *retval);
zend_result dom_node_first_child_read(dom_object *obj, zval *retval);
zend_result dom_node_last_child_read(dom_object *obj, zval *retval);
zend_result dom_node_previous_sibling_read(dom_object *obj, zval *retval);
Expand Down
8 changes: 8 additions & 0 deletions ext/dom/entityreference.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,12 @@ zend_result dom_entity_reference_child_nodes_read(dom_object *obj, zval *retval)
return dom_node_child_nodes_read(obj, retval);
}

zend_result dom_modern_entity_reference_child_nodes_read(dom_object *obj, zval *retval)
{
DOM_PROP_NODE(xmlNodePtr, nodep, obj);

dom_entity_reference_fetch_and_sync_declaration(nodep);
return dom_modern_node_child_nodes_read(obj, retval);
}

#endif
13 changes: 12 additions & 1 deletion ext/dom/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,18 @@ zend_result dom_node_child_nodes_read(dom_object *obj, zval *retval)
{
DOM_PROP_NODE(xmlNodePtr, nodep, obj);

object_init_ex(retval, dom_get_nodelist_ce(php_dom_follow_spec_intern(obj)));
object_init_ex(retval, dom_get_nodelist_ce(false));
dom_object *intern = Z_DOMOBJ_P(retval);
php_dom_create_obj_map(obj, intern, NULL, NULL, NULL, &php_dom_obj_map_child_nodes);

return SUCCESS;
}

zend_result dom_modern_node_child_nodes_read(dom_object *obj, zval *retval)
{
DOM_PROP_NODE(xmlNodePtr, nodep, obj);

object_init_ex(retval, dom_get_nodelist_ce(true));
dom_object *intern = Z_DOMOBJ_P(retval);
php_dom_create_obj_map(obj, intern, NULL, NULL, NULL, &php_dom_obj_map_child_nodes);

Expand Down
4 changes: 2 additions & 2 deletions ext/dom/php_dom.c
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ PHP_MINIT_FUNCTION(dom)
DOM_REGISTER_PROP_HANDLER(&dom_modern_node_prop_handlers, "ownerDocument", dom_node_owner_document_read, NULL);
DOM_REGISTER_PROP_HANDLER(&dom_modern_node_prop_handlers, "parentNode", dom_node_parent_node_read, NULL);
DOM_REGISTER_PROP_HANDLER(&dom_modern_node_prop_handlers, "parentElement", dom_node_parent_element_read, NULL);
DOM_REGISTER_PROP_HANDLER(&dom_modern_node_prop_handlers, "childNodes", dom_node_child_nodes_read, NULL);
DOM_REGISTER_PROP_HANDLER(&dom_modern_node_prop_handlers, "childNodes", dom_modern_node_child_nodes_read, NULL);
DOM_REGISTER_PROP_HANDLER(&dom_modern_node_prop_handlers, "firstChild", dom_node_first_child_read, NULL);
DOM_REGISTER_PROP_HANDLER(&dom_modern_node_prop_handlers, "lastChild", dom_node_last_child_read, NULL);
DOM_REGISTER_PROP_HANDLER(&dom_modern_node_prop_handlers, "previousSibling", dom_node_previous_sibling_read, NULL);
Expand Down Expand Up @@ -1305,7 +1305,7 @@ PHP_MINIT_FUNCTION(dom)
DOM_OVERWRITE_PROP_HANDLER(&dom_modern_entity_reference_prop_handlers, "firstChild", dom_entity_reference_child_read, NULL);
DOM_OVERWRITE_PROP_HANDLER(&dom_modern_entity_reference_prop_handlers, "lastChild", dom_entity_reference_child_read, NULL);
DOM_OVERWRITE_PROP_HANDLER(&dom_modern_entity_reference_prop_handlers, "textContent", dom_entity_reference_text_content_read, NULL);
DOM_OVERWRITE_PROP_HANDLER(&dom_modern_entity_reference_prop_handlers, "childNodes", dom_entity_reference_child_nodes_read, NULL);
DOM_OVERWRITE_PROP_HANDLER(&dom_modern_entity_reference_prop_handlers, "childNodes", dom_modern_entity_reference_child_nodes_read, NULL);
zend_hash_add_new_ptr(&classes, dom_modern_entityreference_class_entry->name, &dom_modern_entity_reference_prop_handlers);

dom_processinginstruction_class_entry = register_class_DOMProcessingInstruction(dom_node_class_entry);
Expand Down
49 changes: 49 additions & 0 deletions ext/dom/tests/modern/common/gh21097.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
--TEST--
GH-21097 (Accessing Dom\Node properties can can throw TypeError(s))
--EXTENSIONS--
dom
--CREDITS--
mbeccati
--FILE--
<?php

$implementation = new \Dom\Implementation();
$node = $implementation->createDocumentType('html', 'publicId', 'systemId');

$r = new \ReflectionClass($node);
foreach ($r->getProperties(\ReflectionProperty::IS_PUBLIC) as $p) {
echo $p->getName(), ": ";
var_dump($node->{$p->getName()});
}

?>
--EXPECT--
nodeType: int(10)
nodeName: string(4) "html"
baseURI: string(11) "about:blank"
isConnected: bool(false)
ownerDocument: NULL
parentNode: NULL
parentElement: NULL
childNodes: object(Dom\NodeList)#24 (1) {
["length"]=>
int(0)
}
firstChild: NULL
lastChild: NULL
previousSibling: NULL
nextSibling: NULL
nodeValue: NULL
textContent: string(0) ""
name: string(4) "html"
entities: object(Dom\DtdNamedNodeMap)#24 (1) {
["length"]=>
int(0)
}
notations: object(Dom\DtdNamedNodeMap)#24 (1) {
["length"]=>
int(0)
}
publicId: string(8) "publicId"
systemId: string(8) "systemId"
internalSubset: NULL
5 changes: 5 additions & 0 deletions ext/mysqli/mysqli_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,11 @@ PHP_FUNCTION(mysqli_options)
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_INITIALIZED);

expected_type = mysqli_options_get_option_zval_type(mysql_option);
if (expected_type == IS_NULL) {
zend_argument_value_error(ERROR_ARG_POS(2), "must be MYSQLI_INIT_COMMAND, MYSQLI_SET_CHARSET_NAME, MYSQLI_SERVER_PUBLIC_KEY, or one of the MYSQLI_OPT_* constants");
RETURN_THROWS();
}

if (expected_type != Z_TYPE_P(mysql_value)) {
switch (expected_type) {
case IS_STRING:
Expand Down
26 changes: 26 additions & 0 deletions ext/mysqli/tests/gh20968.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
GH-20968 mysqli_options() with invalid option should triggers ValueError
--EXTENSIONS--
mysqli
--CONFLICTS--
mysqli
--SKIPIF--
<?php
require_once 'skipifconnectfailure.inc';
?>
--FILE--
<?php
require_once 'connect.inc';

$mysqli = new mysqli($host, $user, $passwd, $db, $port, $socket);

try {
$value = $mysqli->options(10, 'invalid_option');
var_dump($value);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}

?>
--EXPECTF--
mysqli::options(): Argument #%d ($option) must be MYSQLI_INIT_COMMAND, MYSQLI_SET_CHARSET_NAME, MYSQLI_SERVER_PUBLIC_KEY, or one of the MYSQLI_OPT_* constants
13 changes: 8 additions & 5 deletions ext/mysqli/tests/mysqli_options.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ var_dump("MYSQLI_OPT_LOCAL_INFILE", mysqli_options($link, MYSQLI_OPT_LOCAL_INFIL
var_dump("MYSQLI_INIT_COMMAND", mysqli_options($link, MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT=0'));

/* mysqli_real_connect() */
var_dump("MYSQLI_CLIENT_SSL", mysqli_options($link, MYSQLI_CLIENT_SSL, 'not a mysqli_option'));
var_dump("MYSQLI_CLIENT_SSL");

try {
var_dump(mysqli_options($link, MYSQLI_CLIENT_SSL, 'not a mysqli_option'));
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}

mysqli_close($link);

Expand All @@ -81,9 +87,6 @@ try {
echo $e->getMessage() . "\n";
}

// invalid options do not generate errors
mysqli_options($link, -1, "Invalid option");

print "done!";
?>
--EXPECTF--
Expand All @@ -110,7 +113,7 @@ bool(true)
%s(19) "MYSQLI_INIT_COMMAND"
bool(true)
%s(17) "MYSQLI_CLIENT_SSL"
bool(false)
mysqli_options(): Argument #%d ($option) must be MYSQLI_INIT_COMMAND, MYSQLI_SET_CHARSET_NAME, MYSQLI_SERVER_PUBLIC_KEY, or one of the MYSQLI_OPT_* constants
Link closed
mysqli object is already closed
Unknown character set
Expand Down
9 changes: 7 additions & 2 deletions ext/mysqli/tests/mysqli_set_opt.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ require_once 'skipifconnectfailure.inc';
var_dump(mysqli_set_opt($link, MYSQLI_OPT_CONNECT_TIMEOUT, 10));
var_dump(mysqli_set_opt($link, MYSQLI_OPT_LOCAL_INFILE, 1));
var_dump(mysqli_set_opt($link, MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT=0'));
var_dump(mysqli_set_opt($link, MYSQLI_CLIENT_SSL, 'not an mysqli_option'));

try {
var_dump(mysqli_set_opt($link, MYSQLI_CLIENT_SSL, 'not an mysqli_option'));
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}

mysqli_close($link);

Expand All @@ -48,6 +53,6 @@ bool(true)
bool(true)
bool(true)
bool(true)
bool(false)
mysqli_set_opt(): Argument #2 ($option) must be MYSQLI_INIT_COMMAND, MYSQLI_SET_CHARSET_NAME, MYSQLI_SERVER_PUBLIC_KEY, or one of the MYSQLI_OPT_* constants
mysqli object is already closed
done!