mirror of
git://git.sv.gnu.org/coreutils.git
synced 2026-04-17 00:56:34 +02:00
expr: don't interpret argv[0] as an operand
* src/expr.c (main): Given a first argument like -22 (negative, with two or more digits), expr would decrement optind to 0 and then attempt to evaluate argv[0].
This commit is contained in:
@@ -261,6 +261,7 @@ main (int argc, char **argv)
|
||||
{
|
||||
VALUE *v;
|
||||
int c;
|
||||
int saved_optind;
|
||||
|
||||
initialize_main (&argc, &argv);
|
||||
set_program_name (argv[0]);
|
||||
@@ -273,6 +274,7 @@ main (int argc, char **argv)
|
||||
|
||||
/* The argument -0 should not result in an error message. */
|
||||
opterr = 0;
|
||||
saved_optind = 1;
|
||||
|
||||
while ((c = getopt_long (argc, argv, "+", long_options, NULL)) != -1)
|
||||
{
|
||||
@@ -282,7 +284,7 @@ main (int argc, char **argv)
|
||||
*/
|
||||
if ('?' == c)
|
||||
{
|
||||
--optind;
|
||||
optind = saved_optind;
|
||||
break;
|
||||
}
|
||||
else
|
||||
@@ -305,6 +307,7 @@ main (int argc, char **argv)
|
||||
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
}
|
||||
saved_optind = optind;
|
||||
}
|
||||
|
||||
if (argc <= optind)
|
||||
|
||||
Reference in New Issue
Block a user