readgroup: Make sure user supplies a groupfile
authorSimon Wilkinson <sxw@your-file-system.com>
Sat, 2 Mar 2013 11:44:02 +0000 (11:44 +0000)
committerJeffrey Altman <jaltman@your-file-system.com>
Thu, 7 Mar 2013 16:06:25 +0000 (08:06 -0800)
If the user supplies enough command line arguments, but doesn't
provide a groupfile, then we can end up trying to open whatever
garbage is on the stack.

Once we've finished parsing the command line arguments, make sure
that a filename was supplied.

Caught by coverity (#986008)

Change-Id: Iaea60027cf4bd81f9af04e995ce5c395275be833
Reviewed-on: http://gerrit.openafs.org/9440
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>

src/ptserver/readgroup.c

index 8dd0f73..d4a7aaf 100644 (file)
@@ -76,6 +76,8 @@ main(int argc, char **argv)
     afs_int32 i;
     afs_int32 fail = 0;
 
+    buf[0] = '\0';
+
     if (argc < 2) {
        fprintf(stderr, "Usage: readgroup [-v] [-c cellname] groupfile.\n");
        exit(0);
@@ -92,6 +94,13 @@ main(int argc, char **argv)
                strncpy(buf, argv[i], 150);
        }
     }
+
+    /* Catch missing filename */
+    if (buf[0] == '\0') {
+       fprintf(stderr, "Usage: readgroup [-v] [-c cellname] groupfile.\n");
+       exit(0);
+    }
+
     code = pr_Initialize(2, AFSDIR_CLIENT_ETC_DIRPATH, cellname);
     free(cellname);
     if (code) {