up: refuse multicharacter arguments
authorAndrew Deason <adeason@sinenomine.net>
Thu, 3 Jun 2010 14:54:28 +0000 (09:54 -0500)
committerDerrick Brashear <shadow@dementia.org>
Thu, 3 Jun 2010 17:58:11 +0000 (10:58 -0700)
The 'up' command currently silently accepts and discards extra
characters when specifying arguments. This can produce rather
confusing behavior such as mistyping '-v -1' as '-v-1' resulting in
the '-v' switch being honored, but the '-1' being ignored. The same
thing occurs for specifying '-v1', even though the usage message
implies that you can combine arguments.

So instead, report an error message for any arguments specified that
are longer than 2 characters, since they are never valid.

Change-Id: I64846b53248ea1d06d03b6ac1fdb4317ba04b03b
Reviewed-on: http://gerrit.openafs.org/2073
Tested-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Jeffrey Altman <jaltman@openafs.org>
Reviewed-by: Derrick Brashear <shadow@dementia.org>

src/venus/up.c

index 7820755..8663a19 100644 (file)
@@ -125,6 +125,10 @@ ScanArgs(int argc, char *argv[])
     while (argc > 0 && *argv[0] == '-') {
        char *cp = *argv;
 
+       if (strlen(cp) > 2) {
+           goto badoption;
+       }
+
        switch (*++cp) {
        case 'v':
            verbose = 1;
@@ -151,7 +155,10 @@ ScanArgs(int argc, char *argv[])
            break;
 
        default:
-           fprintf(stderr, "Unknown option: '%c'\n", *cp);
+           cp--;
+
+ badoption:
+           fprintf(stderr, "Unknown option: '%s'\n", cp);
            fprintf(stderr, USAGE);
            exit(1);
        }