mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix bug #78323: Code 0 is returned on invalid options
This commit is contained in:
commit
1cccbb8ff1
11 changed files with 177 additions and 5 deletions
1
NEWS
1
NEWS
|
@ -6,6 +6,7 @@ PHP NEWS
|
||||||
. Fixed bug #79146 (cscript can fail to run on some systems). (clarodeus)
|
. Fixed bug #79146 (cscript can fail to run on some systems). (clarodeus)
|
||||||
. Fixed bug #79155 (Property nullability lost when using multiple property
|
. Fixed bug #79155 (Property nullability lost when using multiple property
|
||||||
definition). (Nikita)
|
definition). (Nikita)
|
||||||
|
. Fixed bug #78323 (Code 0 is returned on invalid options). (Ivan Mikheykin)
|
||||||
|
|
||||||
- CURL:
|
- CURL:
|
||||||
. Fixed bug #79078 (Hypothetical use-after-free in curl_multi_add_handle()).
|
. Fixed bug #79078 (Hypothetical use-after-free in curl_multi_add_handle()).
|
||||||
|
|
|
@ -4474,7 +4474,7 @@ PHP_FUNCTION(getopt)
|
||||||
|
|
||||||
while ((o = php_getopt(argc, argv, opts, &php_optarg, &php_optind, 0, 1)) != -1) {
|
while ((o = php_getopt(argc, argv, opts, &php_optarg, &php_optind, 0, 1)) != -1) {
|
||||||
/* Skip unknown arguments. */
|
/* Skip unknown arguments. */
|
||||||
if (o == '?') {
|
if (o == PHP_GETOPT_INVALID_ARG) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#define OPTERRNF (2)
|
#define OPTERRNF (2)
|
||||||
#define OPTERRARG (3)
|
#define OPTERRARG (3)
|
||||||
|
|
||||||
|
// Print error message to stderr and return -2 to distinguish it from '?' command line option.
|
||||||
static int php_opt_error(int argc, char * const *argv, int oint, int optchr, int err, int show_err) /* {{{ */
|
static int php_opt_error(int argc, char * const *argv, int oint, int optchr, int err, int show_err) /* {{{ */
|
||||||
{
|
{
|
||||||
if (show_err)
|
if (show_err)
|
||||||
|
@ -47,7 +48,7 @@ static int php_opt_error(int argc, char * const *argv, int oint, int optchr, int
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return('?');
|
return PHP_GETOPT_INVALID_ARG;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
|
@ -35,4 +35,7 @@ extern PHPAPI int php_optidx;
|
||||||
PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **optarg, int *optind, int show_err, int arg_start);
|
PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], char **optarg, int *optind, int show_err, int arg_start);
|
||||||
END_EXTERN_C()
|
END_EXTERN_C()
|
||||||
|
|
||||||
|
/* php_getopt will return this value if there is an error in arguments */
|
||||||
|
#define PHP_GETOPT_INVALID_ARG (-2)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2282,6 +2282,7 @@ parent_loop_end:
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
case '?':
|
case '?':
|
||||||
|
case PHP_GETOPT_INVALID_ARG:
|
||||||
if (request) {
|
if (request) {
|
||||||
fcgi_destroy_request(request);
|
fcgi_destroy_request(request);
|
||||||
}
|
}
|
||||||
|
@ -2291,6 +2292,9 @@ parent_loop_end:
|
||||||
php_cgi_usage(argv[0]);
|
php_cgi_usage(argv[0]);
|
||||||
php_output_end_all();
|
php_output_end_all();
|
||||||
exit_status = 0;
|
exit_status = 0;
|
||||||
|
if (c == PHP_GETOPT_INVALID_ARG) {
|
||||||
|
exit_status = 1;
|
||||||
|
}
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
41
sapi/cgi/tests/bug78323.phpt
Normal file
41
sapi/cgi/tests/bug78323.phpt
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
--TEST--
|
||||||
|
Bug #78323 Test exit code and error message for invalid parameters
|
||||||
|
--SKIPIF--
|
||||||
|
<?php include "skipif.inc"; ?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
include "include.inc";
|
||||||
|
$php = get_cgi_path();
|
||||||
|
reset_env_vars();
|
||||||
|
|
||||||
|
|
||||||
|
// no argument for option
|
||||||
|
ob_start();
|
||||||
|
passthru("$php --memory-limit=1G 2>&1", $exitCode);
|
||||||
|
$output = ob_get_contents();
|
||||||
|
ob_end_clean();
|
||||||
|
|
||||||
|
$lines = preg_split('/\R/', $output);
|
||||||
|
echo $lines[0], "\n",
|
||||||
|
$lines[1], "\n",
|
||||||
|
"Done: $exitCode\n\n";
|
||||||
|
|
||||||
|
|
||||||
|
// Successful execution
|
||||||
|
ob_start();
|
||||||
|
passthru("$php -dmemory-limit=1G -v", $exitCode);
|
||||||
|
$output = ob_get_contents();
|
||||||
|
ob_end_clean();
|
||||||
|
|
||||||
|
$lines = preg_split('/\R/', $output);
|
||||||
|
echo $lines[0], "\n",
|
||||||
|
"Done: $exitCode\n";
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
Error in argument 1, char 1: no argument for option -
|
||||||
|
Usage: %s
|
||||||
|
Done: 1
|
||||||
|
|
||||||
|
PHP %s
|
||||||
|
Done: 0
|
|
@ -1228,7 +1228,7 @@ int main(int argc, char *argv[])
|
||||||
setmode(_fileno(stderr), O_BINARY); /* make the stdio mode be binary */
|
setmode(_fileno(stderr), O_BINARY); /* make the stdio mode be binary */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2))!=-1) {
|
while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 1, 2))!=-1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'c':
|
case 'c':
|
||||||
if (ini_path_override) {
|
if (ini_path_override) {
|
||||||
|
@ -1280,6 +1280,10 @@ int main(int argc, char *argv[])
|
||||||
case '?':
|
case '?':
|
||||||
php_cli_usage(argv[0]);
|
php_cli_usage(argv[0]);
|
||||||
goto out;
|
goto out;
|
||||||
|
case PHP_GETOPT_INVALID_ARG: /* print usage on bad options, exit 1 */
|
||||||
|
php_cli_usage(argv[0]);
|
||||||
|
exit_status = 1;
|
||||||
|
goto out;
|
||||||
case 'i': case 'v': case 'm':
|
case 'i': case 'v': case 'm':
|
||||||
sapi_module = &cli_sapi_module;
|
sapi_module = &cli_sapi_module;
|
||||||
goto exit_loop;
|
goto exit_loop;
|
||||||
|
|
|
@ -16,7 +16,7 @@ $php = getenv('TEST_PHP_EXECUTABLE');
|
||||||
echo `"$php" -n --version | grep built:`;
|
echo `"$php" -n --version | grep built:`;
|
||||||
echo `echo "<?php print_r(\\\$argv);" | "$php" -n -- foo bar baz`, "\n";
|
echo `echo "<?php print_r(\\\$argv);" | "$php" -n -- foo bar baz`, "\n";
|
||||||
echo `"$php" -n --version foo bar baz | grep built:`;
|
echo `"$php" -n --version foo bar baz | grep built:`;
|
||||||
echo `"$php" -n --notexisting foo bar baz | grep Usage:`;
|
echo `"$php" -n --notexisting foo bar baz 2>&1 | grep Usage:`;
|
||||||
|
|
||||||
echo "Done\n";
|
echo "Done\n";
|
||||||
?>
|
?>
|
||||||
|
|
78
sapi/cli/tests/bug78323.phpt
Normal file
78
sapi/cli/tests/bug78323.phpt
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
--TEST--
|
||||||
|
Bug #78323 Test exit code and error message for invalid parameters
|
||||||
|
--SKIPIF--
|
||||||
|
<?php
|
||||||
|
include "skipif.inc";
|
||||||
|
?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
$php = getenv('TEST_PHP_EXECUTABLE');
|
||||||
|
|
||||||
|
// There are 3 types of option errors:
|
||||||
|
// 1 : in flags
|
||||||
|
// 2 option not found
|
||||||
|
// 3 no argument for option
|
||||||
|
|
||||||
|
|
||||||
|
// colon in flags
|
||||||
|
ob_start();
|
||||||
|
passthru("$php -a:Z 2>&1", $exitCode);
|
||||||
|
$output = ob_get_contents();
|
||||||
|
ob_end_clean();
|
||||||
|
|
||||||
|
$lines = preg_split('/\R/', $output);
|
||||||
|
echo $lines[0], "\n",
|
||||||
|
$lines[1], "\n",
|
||||||
|
"Done: $exitCode\n\n";
|
||||||
|
|
||||||
|
|
||||||
|
// option not found
|
||||||
|
ob_start();
|
||||||
|
passthru("$php -Z 2>&1", $exitCode);
|
||||||
|
$output = ob_get_contents();
|
||||||
|
ob_end_clean();
|
||||||
|
|
||||||
|
$lines = preg_split('/\R/', $output);
|
||||||
|
echo $lines[0], "\n",
|
||||||
|
$lines[1], "\n",
|
||||||
|
"Done: $exitCode\n\n";
|
||||||
|
|
||||||
|
|
||||||
|
// no argument for option
|
||||||
|
ob_start();
|
||||||
|
passthru("$php --memory-limit=1G 2>&1", $exitCode);
|
||||||
|
$output = ob_get_contents();
|
||||||
|
ob_end_clean();
|
||||||
|
|
||||||
|
$lines = preg_split('/\R/', $output);
|
||||||
|
echo $lines[0], "\n",
|
||||||
|
$lines[1], "\n",
|
||||||
|
"Done: $exitCode\n\n";
|
||||||
|
|
||||||
|
|
||||||
|
// Successful execution
|
||||||
|
ob_start();
|
||||||
|
passthru("$php -dmemory-limit=1G -v", $exitCode);
|
||||||
|
$output = ob_get_contents();
|
||||||
|
ob_end_clean();
|
||||||
|
|
||||||
|
$lines = preg_split('/\R/', $output);
|
||||||
|
echo $lines[0], "\n",
|
||||||
|
"Done: $exitCode\n";
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
Error in argument %d, char %d: : in flags
|
||||||
|
Usage: %s [options] [-f] <file> [--] [args...]
|
||||||
|
Done: 1
|
||||||
|
|
||||||
|
Error in argument %d, char %d: option not found %s
|
||||||
|
Usage: %s [options] [-f] <file> [--] [args...]
|
||||||
|
Done: 1
|
||||||
|
|
||||||
|
Error in argument %d, char %d: no argument for option %s
|
||||||
|
Usage: %s [options] [-f] <file> [--] [args...]
|
||||||
|
Done: 1
|
||||||
|
|
||||||
|
PHP %s
|
||||||
|
Done: 0
|
|
@ -1697,6 +1697,7 @@ int main(int argc, char *argv[])
|
||||||
default:
|
default:
|
||||||
case 'h':
|
case 'h':
|
||||||
case '?':
|
case '?':
|
||||||
|
case PHP_GETOPT_INVALID_ARG:
|
||||||
cgi_sapi_module.startup(&cgi_sapi_module);
|
cgi_sapi_module.startup(&cgi_sapi_module);
|
||||||
php_output_activate();
|
php_output_activate();
|
||||||
SG(headers_sent) = 1;
|
SG(headers_sent) = 1;
|
||||||
|
@ -1704,7 +1705,7 @@ int main(int argc, char *argv[])
|
||||||
php_output_end_all();
|
php_output_end_all();
|
||||||
php_output_deactivate();
|
php_output_deactivate();
|
||||||
fcgi_shutdown();
|
fcgi_shutdown();
|
||||||
exit_status = (c == 'h') ? FPM_EXIT_OK : FPM_EXIT_USAGE;
|
exit_status = (c != PHP_GETOPT_INVALID_ARG) ? FPM_EXIT_OK : FPM_EXIT_USAGE;
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
case 'v': /* show php version & quit */
|
case 'v': /* show php version & quit */
|
||||||
|
|
39
sapi/fpm/tests/bug78323.phpt
Normal file
39
sapi/fpm/tests/bug78323.phpt
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
--TEST--
|
||||||
|
FPM: Bug #78323 Test exit code for invalid parameters
|
||||||
|
--SKIPIF--
|
||||||
|
<?php include "skipif.inc"; ?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once "tester.inc";
|
||||||
|
|
||||||
|
$php = \FPM\Tester::findExecutable();
|
||||||
|
|
||||||
|
// no argument for option
|
||||||
|
ob_start();
|
||||||
|
passthru("$php --memory-limit=1G 2>&1", $exitCode);
|
||||||
|
$output = ob_get_contents();
|
||||||
|
ob_end_clean();
|
||||||
|
|
||||||
|
$lines = preg_split('/\R/', $output);
|
||||||
|
echo $lines[0], "\n",
|
||||||
|
"Done: $exitCode\n\n";
|
||||||
|
|
||||||
|
|
||||||
|
// Successful execution
|
||||||
|
ob_start();
|
||||||
|
passthru("$php -dmemory-limit=1G -v", $exitCode);
|
||||||
|
$output = ob_get_contents();
|
||||||
|
ob_end_clean();
|
||||||
|
|
||||||
|
$lines = preg_split('/\R/', $output);
|
||||||
|
echo $lines[0], "\n",
|
||||||
|
"Done: $exitCode\n";
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
Usage: %s
|
||||||
|
Done: 64
|
||||||
|
|
||||||
|
PHP %s
|
||||||
|
Done: 0
|
Loading…
Add table
Add a link
Reference in a new issue