pt_util: Catch sscanf failures
authorSimon Wilkinson <sxw@your-file-system.com>
Wed, 27 Feb 2013 09:21:30 +0000 (09:21 +0000)
committerJeffrey Altman <jaltman@your-file-system.com>
Wed, 27 Feb 2013 20:42:24 +0000 (12:42 -0800)
If there isn't sufficient data in the input line to satisfy sscanf,
fail with an error, rather than continuing with potentially corrupt
data.

Change-Id: I5f963b5623176ac7631693b093d23cf9f0405edc
Reviewed-on: http://gerrit.openafs.org/9295
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/pt_util.c

index 58288ef..f1e9c39 100644 (file)
@@ -237,7 +237,12 @@ CommandProc(struct cmd_syndesc *a_as, void *arock)
            char name[PR_MAXNAMELEN], mem[PR_MAXNAMELEN];
 
            if (isspace(*buffer)) {
-               sscanf(buffer, "%s %d", mem, &uid);
+               code = sscanf(buffer, "%s %d", mem, &uid);
+               if (code != 2) {
+                   fprintf(stderr,
+                           "Insuffient data provided for group membership\n");
+                   exit(1);
+               }
 
                for (u = usr_head; u; u = u->next)
                    if (u->uid && u->uid == uid)
@@ -287,8 +292,13 @@ CommandProc(struct cmd_syndesc *a_as, void *arock)
                    fprintf(stderr, "Error while adding %s to %s: %s\n", mem,
                            name, afs_error_message(code));
            } else {
-               sscanf(buffer, "%s %d/%d %d %d %d", name, &flags, &quota, &id,
-                      &oid, &cid);
+               code = sscanf(buffer, "%s %d/%d %d %d %d", name, &flags, &quota, &id,
+                             &oid, &cid);
+               if (code != 6) {
+                   fprintf(stderr,
+                           "Insufficient data provided for user/group\n");
+                   exit(1);
+               }
 
                if (FindByID(0, id))
                    code = PRIDEXIST;