com php-src: Fixed bug #77561: NEWS Zend/zend_language_scan ner.l main/main.c sapi/cli/tests/bug77561.i nc sapi/cli/tests/bug77561.phpt
| From: | Nikita Popov | Date: | Mon, 10 Aug 2020 08:38:33 +0000 |
| Subject: | com php-src: Fixed bug #77561: NEWS Zend/zend_language_scan ner.l main/main.c sapi/cli/tests/bug77561.i nc sapi/cli/tests/bug77561.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-112626@lists.php.net to get a copy of this message | ||
Commit: 896dad4c794f7826812bcfdbaaa9f0b3518d9385
Author: Nikita Popov <nikita.ppv@gmail.com> Mon, 10 Aug 2020 10:38:33 +0200
Parents: 74c43818066585a5155c6c07b46b3d1727fd14b8
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=896dad4c794f7826812bcfdbaaa9f0b3518d9385
Log:
Fixed bug #77561
Unconditionally strip shebang lines when using the CLI SAPI,
independently of whether they occur in the primary or non-primary
script. It's unlikely that someone intentionally wants to print
that shebang line when including a script, and this regularly
causes issues when scripts are used in multiple contexts, e.g.
for direct invocation and as a phar bootstrap.
Bugs:
https://bugs.php.net/77561
Changed paths:
M NEWS
M Zend/zend_language_scanner.l
M main/main.c
A sapi/cli/tests/bug77561.inc
A sapi/cli/tests/bug77561.phpt
Diff:
diff --git a/NEWS b/NEWS
index 9a5c78f9cf9..0ed3122f90f 100644
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,8 @@ PHP NEWS
. Fixed bug #79897 (Promoted constructor params with attribs cause crash).
(Deus Kane)
. Fixed bug #79946 (Build fails due to undeclared UINT32_C). (Nikita)
+ . Fixed bug #77561 (Shebang line not stripped for non-primary script).
+ (Nikita)
- Date:
. Fixed bug #60302 (DateTime::createFromFormat should new static(), not new
diff --git a/Zend/zend_language_scanner.l b/Zend/zend_language_scanner.l
index ca5804f4bff..c5f897419d1 100644
--- a/Zend/zend_language_scanner.l
+++ b/Zend/zend_language_scanner.l
@@ -576,7 +576,6 @@ ZEND_API int open_file_for_scanning(zend_file_handle *file_handle)
}
if (CG(skip_shebang)) {
- CG(skip_shebang) = 0;
BEGIN(SHEBANG);
} else {
BEGIN(INITIAL);
diff --git a/main/main.c b/main/main.c
index b90484f1592..390b08c4aa9 100644
--- a/main/main.c
+++ b/main/main.c
@@ -2533,20 +2533,7 @@ PHPAPI int php_execute_script(zend_file_handle *primary_file)
zend_set_timeout(INI_INT("max_execution_time"), 0);
}
- /*
- If cli primary file has shebang line and there is a prepend file,
- the
skip_shebang will be used by prepend file but not primary file,
- save it and restore after prepend file been executed.
- */
- if (CG(skip_shebang) && prepend_file_p) {
- CG(skip_shebang) = 0;
- if (zend_execute_scripts(ZEND_REQUIRE, NULL, 1, prepend_file_p) == SUCCESS) {
- CG(skip_shebang) = 1;
- retval = (zend_execute_scripts(ZEND_REQUIRE, NULL, 2, primary_file, append_file_p) == SUCCESS);
- }
- } else {
- retval = (zend_execute_scripts(ZEND_REQUIRE, NULL, 3, prepend_file_p, primary_file,
append_file_p) == SUCCESS);
- }
+ retval = (zend_execute_scripts(ZEND_REQUIRE, NULL, 3, prepend_file_p, primary_file,
append_file_p) == SUCCESS);
} zend_end_try();
if (EG(exception)) {
diff --git a/sapi/cli/tests/bug77561.inc b/sapi/cli/tests/bug77561.inc
new file mode 100644
index 00000000000..e0ae5b2d13a
--- /dev/null
+++ b/sapi/cli/tests/bug77561.inc
@@ -0,0 +1,4 @@
+#!/usr/bin/env php
+<?php
+declare(strict_types=1);
+echo "Test\n";
diff --git a/sapi/cli/tests/bug77561.phpt b/sapi/cli/tests/bug77561.phpt
new file mode 100644
index 00000000000..42ce9b53dba
--- /dev/null
+++ b/sapi/cli/tests/bug77561.phpt
@@ -0,0 +1,10 @@
+--TEST--
+Bug #77561: Shebang line not stripped for non-primary script
+--FILE--
+<?php
+
+require __DIR__ . '/bug77561.inc';
+
+?>
+--EXPECT--
+Test