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
30 changes: 15 additions & 15 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -2743,7 +2743,7 @@ static void zend_check_magic_method_static(
}

static void zend_check_magic_method_public(
const zend_class_entry *ce, const zend_function *fptr, int error_type)
const zend_class_entry *ce, const zend_function *fptr)
{
// TODO: Remove this warning after adding proper visibility handling.
if (!(fptr->common.fn_flags & ZEND_ACC_PUBLIC)) {
Expand Down Expand Up @@ -2786,77 +2786,77 @@ ZEND_API void zend_check_magic_method_implementation(const zend_class_entry *ce,
} else if (zend_string_equals_literal(lcname, ZEND_GET_FUNC_NAME)) {
zend_check_magic_method_args(1, ce, fptr, error_type);
zend_check_magic_method_non_static(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr);
zend_check_magic_method_arg_type(0, ce, fptr, error_type, MAY_BE_STRING);
} else if (zend_string_equals_literal(lcname, ZEND_SET_FUNC_NAME)) {
zend_check_magic_method_args(2, ce, fptr, error_type);
zend_check_magic_method_non_static(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr);
zend_check_magic_method_arg_type(0, ce, fptr, error_type, MAY_BE_STRING);
zend_check_magic_method_return_type(ce, fptr, error_type, MAY_BE_VOID);
} else if (zend_string_equals_literal(lcname, ZEND_UNSET_FUNC_NAME)) {
zend_check_magic_method_args(1, ce, fptr, error_type);
zend_check_magic_method_non_static(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr);
zend_check_magic_method_arg_type(0, ce, fptr, error_type, MAY_BE_STRING);
zend_check_magic_method_return_type(ce, fptr, error_type, MAY_BE_VOID);
} else if (zend_string_equals_literal(lcname, ZEND_ISSET_FUNC_NAME)) {
zend_check_magic_method_args(1, ce, fptr, error_type);
zend_check_magic_method_non_static(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr);
zend_check_magic_method_arg_type(0, ce, fptr, error_type, MAY_BE_STRING);
zend_check_magic_method_return_type(ce, fptr, error_type, MAY_BE_BOOL);
} else if (zend_string_equals_literal(lcname, ZEND_CALL_FUNC_NAME)) {
zend_check_magic_method_args(2, ce, fptr, error_type);
zend_check_magic_method_non_static(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr);
zend_check_magic_method_arg_type(0, ce, fptr, error_type, MAY_BE_STRING);
zend_check_magic_method_arg_type(1, ce, fptr, error_type, MAY_BE_ARRAY);
} else if (zend_string_equals_literal(lcname, ZEND_CALLSTATIC_FUNC_NAME)) {
zend_check_magic_method_args(2, ce, fptr, error_type);
zend_check_magic_method_static(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr);
zend_check_magic_method_arg_type(0, ce, fptr, error_type, MAY_BE_STRING);
zend_check_magic_method_arg_type(1, ce, fptr, error_type, MAY_BE_ARRAY);
} else if (zend_string_equals_literal(lcname, ZEND_TOSTRING_FUNC_NAME)) {
zend_check_magic_method_args(0, ce, fptr, error_type);
zend_check_magic_method_non_static(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr);
zend_check_magic_method_return_type(ce, fptr, error_type, MAY_BE_STRING);
} else if (zend_string_equals_literal(lcname, ZEND_DEBUGINFO_FUNC_NAME)) {
zend_check_magic_method_args(0, ce, fptr, error_type);
zend_check_magic_method_non_static(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr);
zend_check_magic_method_return_type(ce, fptr, error_type, (MAY_BE_ARRAY | MAY_BE_NULL));
} else if (zend_string_equals_literal(lcname, "__serialize")) {
zend_check_magic_method_args(0, ce, fptr, error_type);
zend_check_magic_method_non_static(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr);
zend_check_magic_method_return_type(ce, fptr, error_type, MAY_BE_ARRAY);
} else if (zend_string_equals_literal(lcname, "__unserialize")) {
zend_check_magic_method_args(1, ce, fptr, error_type);
zend_check_magic_method_non_static(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr);
zend_check_magic_method_arg_type(0, ce, fptr, error_type, MAY_BE_ARRAY);
zend_check_magic_method_return_type(ce, fptr, error_type, MAY_BE_VOID);
} else if (zend_string_equals_literal(lcname, "__set_state")) {
zend_check_magic_method_args(1, ce, fptr, error_type);
zend_check_magic_method_static(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr);
zend_check_magic_method_arg_type(0, ce, fptr, error_type, MAY_BE_ARRAY);
zend_check_magic_method_return_type(ce, fptr, error_type, MAY_BE_OBJECT);
} else if (zend_string_equals(lcname, ZSTR_KNOWN(ZEND_STR_MAGIC_INVOKE))) {
zend_check_magic_method_non_static(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr);
} else if (zend_string_equals(lcname, ZSTR_KNOWN(ZEND_STR_SLEEP))) {
zend_check_magic_method_args(0, ce, fptr, error_type);
zend_check_magic_method_non_static(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr);
zend_check_magic_method_return_type(ce, fptr, error_type, MAY_BE_ARRAY);
} else if (zend_string_equals(lcname, ZSTR_KNOWN(ZEND_STR_WAKEUP))) {
zend_check_magic_method_args(0, ce, fptr, error_type);
zend_check_magic_method_non_static(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr, error_type);
zend_check_magic_method_public(ce, fptr);
zend_check_magic_method_return_type(ce, fptr, error_type, MAY_BE_VOID);
}
}
Expand Down
14 changes: 7 additions & 7 deletions Zend/zend_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,7 @@ static ZEND_COLD bool zend_ast_var_needs_braces(char ch)
return ch == '[' || zend_ast_valid_var_char(ch);
}

static ZEND_COLD void zend_ast_export_var(smart_str *str, zend_ast *ast, int priority, int indent)
static ZEND_COLD void zend_ast_export_var(smart_str *str, zend_ast *ast, int indent)
{
if (ast->kind == ZEND_AST_ZVAL) {
zval *zv = zend_ast_get_zval(ast);
Expand Down Expand Up @@ -2417,7 +2417,7 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
/* 1 child node */
case ZEND_AST_VAR:
smart_str_appendc(str, '$');
zend_ast_export_var(str, ast->child[0], 0, indent);
zend_ast_export_var(str, ast->child[0], indent);
break;
case ZEND_AST_CONST:
zend_ast_export_ns_name(str, ast->child[0], 0, indent);
Expand Down Expand Up @@ -2532,12 +2532,12 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
case ZEND_AST_NULLSAFE_PROP:
zend_ast_export_ex(str, ast->child[0], 0, indent);
smart_str_appends(str, ast->kind == ZEND_AST_NULLSAFE_PROP ? "?->" : "->");
zend_ast_export_var(str, ast->child[1], 0, indent);
zend_ast_export_var(str, ast->child[1], indent);
break;
case ZEND_AST_STATIC_PROP:
zend_ast_export_ns_name(str, ast->child[0], 0, indent);
smart_str_appends(str, "::$");
zend_ast_export_var(str, ast->child[1], 0, indent);
zend_ast_export_var(str, ast->child[1], indent);
break;
case ZEND_AST_CALL: {
zend_ast *left = ast->child[0];
Expand Down Expand Up @@ -2857,15 +2857,15 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
case ZEND_AST_NULLSAFE_METHOD_CALL:
zend_ast_export_ex(str, ast->child[0], 0, indent);
smart_str_appends(str, ast->kind == ZEND_AST_NULLSAFE_METHOD_CALL ? "?->" : "->");
zend_ast_export_var(str, ast->child[1], 0, indent);
zend_ast_export_var(str, ast->child[1], indent);
smart_str_appendc(str, '(');
zend_ast_export_ex(str, ast->child[2], 0, indent);
smart_str_appendc(str, ')');
break;
case ZEND_AST_STATIC_CALL:
zend_ast_export_ns_name(str, ast->child[0], 0, indent);
smart_str_appends(str, "::");
zend_ast_export_var(str, ast->child[1], 0, indent);
zend_ast_export_var(str, ast->child[1], indent);
smart_str_appendc(str, '(');
zend_ast_export_ex(str, ast->child[2], 0, indent);
smart_str_appendc(str, ')');
Expand Down Expand Up @@ -2901,7 +2901,7 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
zend_ast_export_catch_name_list(str, zend_ast_get_list(ast->child[0]), indent);
if (ast->child[1]) {
smart_str_appends(str, " $");
zend_ast_export_var(str, ast->child[1], 0, indent);
zend_ast_export_var(str, ast->child[1], indent);
}
smart_str_appends(str, ") {\n");
zend_ast_export_stmt(str, ast->child[2], indent + 1);
Expand Down
5 changes: 2 additions & 3 deletions Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -2185,8 +2185,7 @@ static zend_property_info *zend_get_prop_not_accepting_double(zend_reference *re
return NULL;
}

static ZEND_COLD zend_long zend_throw_incdec_ref_error(
zend_reference *ref, zend_property_info *error_prop OPLINE_DC)
static ZEND_COLD zend_long zend_throw_incdec_ref_error(zend_property_info *error_prop OPLINE_DC)
{
zend_string *type_str = zend_type_to_string(error_prop->type);
if (ZEND_IS_INCREMENT(opline->opcode)) {
Expand Down Expand Up @@ -2247,7 +2246,7 @@ static void zend_incdec_typed_ref(zend_reference *ref, zval *copy OPLINE_DC EXEC
if (UNEXPECTED(Z_TYPE_P(var_ptr) == IS_DOUBLE) && Z_TYPE_P(copy) == IS_LONG) {
zend_property_info *error_prop = zend_get_prop_not_accepting_double(ref);
if (UNEXPECTED(error_prop)) {
zend_long val = zend_throw_incdec_ref_error(ref, error_prop OPLINE_CC);
zend_long val = zend_throw_incdec_ref_error(error_prop OPLINE_CC);
ZVAL_LONG(var_ptr, val);
}
} else if (UNEXPECTED(!zend_verify_ref_assignable_zval(ref, var_ptr, EX_USES_STRICT_TYPES()))) {
Expand Down
1 change: 1 addition & 0 deletions ext/dom/dom_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ zend_result dom_modern_node_prefix_read(dom_object *obj, zval *retval);
zend_result dom_node_prefix_write(dom_object *obj, zval *newval);
zend_result dom_node_local_name_read(dom_object *obj, zval *retval);
zend_result dom_node_base_uri_read(dom_object *obj, zval *retval);
zend_result dom_modern_node_base_uri_read(dom_object *obj, zval *retval);
zend_result dom_node_text_content_read(dom_object *obj, zval *retval);
zend_result dom_node_text_content_write(dom_object *obj, zval *newval);

Expand Down
25 changes: 18 additions & 7 deletions ext/dom/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,14 +666,25 @@ zend_result dom_node_base_uri_read(dom_object *obj, zval *retval)
ZVAL_STRING(retval, (const char *) baseuri);
xmlFree(baseuri);
} else {
if (php_dom_follow_spec_intern(obj)) {
if (nodep->doc->URL) {
ZVAL_STRING(retval, (const char *) nodep->doc->URL);
} else {
ZVAL_STRING(retval, "about:blank");
}
ZVAL_NULL(retval);
}

return SUCCESS;
}

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

xmlChar *baseuri = xmlNodeGetBase(nodep->doc, nodep);
if (baseuri) {
ZVAL_STRING(retval, (const char *) baseuri);
xmlFree(baseuri);
} else {
if (nodep->doc && nodep->doc->URL) {
ZVAL_STRING(retval, (const char *) nodep->doc->URL);
} else {
ZVAL_NULL(retval);
ZVAL_STRING(retval, "about:blank");
}
}

Expand Down
2 changes: 1 addition & 1 deletion ext/dom/php_dom.c
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ PHP_MINIT_FUNCTION(dom)
zend_hash_init(&dom_modern_node_prop_handlers, 0, NULL, NULL, true);
DOM_REGISTER_PROP_HANDLER(&dom_modern_node_prop_handlers, "nodeType", dom_node_node_type_read, NULL);
DOM_REGISTER_PROP_HANDLER(&dom_modern_node_prop_handlers, "nodeName", dom_node_node_name_read, NULL);
DOM_REGISTER_PROP_HANDLER(&dom_modern_node_prop_handlers, "baseURI", dom_node_base_uri_read, NULL);
DOM_REGISTER_PROP_HANDLER(&dom_modern_node_prop_handlers, "baseURI", dom_modern_node_base_uri_read, NULL);
DOM_REGISTER_PROP_HANDLER(&dom_modern_node_prop_handlers, "isConnected", dom_node_is_connected_read, NULL);
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);
Expand Down
28 changes: 28 additions & 0 deletions ext/dom/tests/modern/common/gh21077.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
GH-21077 (Accessing Dom\Node::baseURI can throw TypeError)
--EXTENSIONS--
dom
--CREDITS--
mbeccati
--FILE--
<?php

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

var_dump($node->baseURI);

$dom = Dom\XMLDocument::createEmpty();
$dom->append($node = $dom->importNode($node));

var_dump($dom->saveXML());

var_dump($node->baseURI);

?>
--EXPECT--
string(11) "about:blank"
string(84) "<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "publicId" "systemId">
"
string(11) "about:blank"
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object(Dom\DocumentType)#3 (19) {
["nodeName"]=>
string(5) "qname"
["baseURI"]=>
NULL
string(11) "about:blank"
["isConnected"]=>
bool(false)
["parentNode"]=>
Expand Down Expand Up @@ -86,7 +86,7 @@ object(Dom\DocumentType)#2 (19) {
["nodeName"]=>
string(5) "qname"
["baseURI"]=>
NULL
string(11) "about:blank"
["isConnected"]=>
bool(false)
["parentNode"]=>
Expand Down Expand Up @@ -129,7 +129,7 @@ object(Dom\DocumentType)#1 (19) {
["nodeName"]=>
string(5) "qname"
["baseURI"]=>
NULL
string(11) "about:blank"
["isConnected"]=>
bool(false)
["parentNode"]=>
Expand Down Expand Up @@ -172,7 +172,7 @@ object(Dom\DocumentType)#4 (19) {
["nodeName"]=>
string(5) "qname"
["baseURI"]=>
NULL
string(11) "about:blank"
["isConnected"]=>
bool(false)
["parentNode"]=>
Expand Down
2 changes: 1 addition & 1 deletion ext/dom/tests/modern/xml/DTDNamedNodeMap.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ object(Dom\Notation)#4 (13) {
["nodeName"]=>
string(3) "GIF"
["baseURI"]=>
NULL
string(11) "about:blank"
["isConnected"]=>
bool(false)
["parentNode"]=>
Expand Down
Loading