summaryrefslogtreecommitdiff
path: root/sapi/cgi
diff options
context:
space:
mode:
authorIvan Mikheykin <ivan.mikheykin@flant.com>2020-01-17 22:26:35 +0300
committerNikita Popov <nikita.ppv@gmail.com>2020-01-27 13:32:19 +0100
commitfd08f062ae5a3c92bfc0345da7e83ab320046864 (patch)
tree23ca98cfd88487284bfbf3536ad7d4c62c47008b /sapi/cgi
parentb836d9cdc161c10d7c4b4eeb50ab123725967893 (diff)
downloadphp-git-fd08f062ae5a3c92bfc0345da7e83ab320046864.tar.gz
Fix bug #78323: Code 0 is returned on invalid options
Set CLI exit code to 1 when invalid parameters are passed, and print error to stderr.
Diffstat (limited to 'sapi/cgi')
-rw-r--r--sapi/cgi/cgi_main.c4
-rw-r--r--sapi/cgi/tests/bug78323.phpt41
2 files changed, 45 insertions, 0 deletions
diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c
index fb16f2b577..d6449ba228 100644
--- a/sapi/cgi/cgi_main.c
+++ b/sapi/cgi/cgi_main.c
@@ -2283,6 +2283,7 @@ parent_loop_end:
break;
case 'h':
case '?':
+ case PHP_GETOPT_INVALID_ARG:
if (request) {
fcgi_destroy_request(request);
}
@@ -2292,6 +2293,9 @@ parent_loop_end:
php_cgi_usage(argv[0]);
php_output_end_all();
exit_status = 0;
+ if (c == PHP_GETOPT_INVALID_ARG) {
+ exit_status = 1;
+ }
goto out;
}
}
diff --git a/sapi/cgi/tests/bug78323.phpt b/sapi/cgi/tests/bug78323.phpt
new file mode 100644
index 0000000000..d89e51874a
--- /dev/null
+++ b/sapi/cgi/tests/bug78323.phpt
@@ -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