diff options
author | Jim Meyering <meyering@redhat.com> | 2008-10-15 09:19:29 +0200 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2008-10-15 15:34:58 +0200 |
commit | 514b7fbc0069bbd53087561020b1562ccbcd11ee (patch) | |
tree | 2e828748c2f5a4de5e79f6e79335b0cfe54f3f4d /src | |
parent | 555c219d9eff5b0b15be7c479a8efc81f59b0ffb (diff) | |
download | coreutils-514b7fbc0069bbd53087561020b1562ccbcd11ee.tar.xz |
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].
Diffstat (limited to 'src')
-rw-r--r-- | src/expr.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/expr.c b/src/expr.c index dc4161602..b7bec646b 100644 --- a/src/expr.c +++ b/src/expr.c @@ -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) |