summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-10-12 16:34:19 +0200
committerNikita Popov <nikita.ppv@gmail.com>2020-10-12 16:35:09 +0200
commitf9b7609d17694c5b5d5bba6321b27944220566be (patch)
treedc00373f44e26c1d81c8d5ef885cecd987f0f2a8
parent11c752a5f5c0fb23e87e8cb9c4147f1a5374fe06 (diff)
downloadphp-git-f9b7609d17694c5b5d5bba6321b27944220566be.tar.gz
Fixed bug #80225
Namespaced and declares have a different interpretation of what "first statement" means.
-rw-r--r--NEWS3
-rw-r--r--Zend/tests/namespace_first_stmt_nop.phpt10
-rw-r--r--Zend/zend_compile.c13
3 files changed, 20 insertions, 6 deletions
diff --git a/NEWS b/NEWS
index 85e48c5e0e..86d1f2994d 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,9 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.0.0rc2
+- Core:
+ . Fixed bug #80225 (broken namespace usage in eval code). (Nikita)
+
- Curl:
. Fixed bug #80121 (Null pointer deref if CurlHandle directly instantiated).
(Nikita)
diff --git a/Zend/tests/namespace_first_stmt_nop.phpt b/Zend/tests/namespace_first_stmt_nop.phpt
new file mode 100644
index 0000000000..8f26fdc859
--- /dev/null
+++ b/Zend/tests/namespace_first_stmt_nop.phpt
@@ -0,0 +1,10 @@
+--TEST--
+Nop statement before namespace
+--FILE--
+<?php
+;
+namespace Foo;
+?>
+===DONE===
+--EXPECT--
+===DONE===
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 7debd55acc..d5318f30a5 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -5865,7 +5865,7 @@ zend_bool zend_handle_encoding_declaration(zend_ast *ast) /* {{{ */
/* }}} */
/* Check whether this is the first statement, not counting declares. */
-static zend_result zend_is_first_statement(zend_ast *ast) /* {{{ */
+static zend_result zend_is_first_statement(zend_ast *ast, zend_bool allow_nop) /* {{{ */
{
uint32_t i = 0;
zend_ast_list *file_ast = zend_ast_get_list(CG(ast));
@@ -5874,8 +5874,9 @@ static zend_result zend_is_first_statement(zend_ast *ast) /* {{{ */
if (file_ast->child[i] == ast) {
return SUCCESS;
} else if (file_ast->child[i] == NULL) {
- /* Empty statements count as statements. */
- return FAILURE;
+ if (!allow_nop) {
+ return FAILURE;
+ }
} else if (file_ast->child[i]->kind != ZEND_AST_DECLARE) {
return FAILURE;
}
@@ -5909,14 +5910,14 @@ void zend_compile_declare(zend_ast *ast) /* {{{ */
zval_ptr_dtor_nogc(&value_zv);
} else if (zend_string_equals_literal_ci(name, "encoding")) {
- if (FAILURE == zend_is_first_statement(ast)) {
+ if (FAILURE == zend_is_first_statement(ast, /* allow_nop */ 0)) {
zend_error_noreturn(E_COMPILE_ERROR, "Encoding declaration pragma must be "
"the very first statement in the script");
}
} else if (zend_string_equals_literal_ci(name, "strict_types")) {
zval value_zv;
- if (FAILURE == zend_is_first_statement(ast)) {
+ if (FAILURE == zend_is_first_statement(ast, /* allow_nop */ 0)) {
zend_error_noreturn(E_COMPILE_ERROR, "strict_types declaration must be "
"the very first statement in the script");
}
@@ -7669,7 +7670,7 @@ void zend_compile_namespace(zend_ast *ast) /* {{{ */
zend_bool is_first_namespace = (!with_bracket && !FC(current_namespace))
|| (with_bracket && !FC(has_bracketed_namespaces));
- if (is_first_namespace && FAILURE == zend_is_first_statement(ast)) {
+ if (is_first_namespace && FAILURE == zend_is_first_statement(ast, /* allow_nop */ 1)) {
zend_error_noreturn(E_COMPILE_ERROR, "Namespace declaration statement has to be "
"the very first statement or after any declare call in the script");
}