salvager: Do not abort on large volume IDs
authorAndrew Deason <adeason@sinenomine.net>
Thu, 10 Mar 2011 20:55:50 +0000 (14:55 -0600)
committerDerrick Brashear <shadow@dementia.org>
Fri, 11 Mar 2011 00:24:54 +0000 (16:24 -0800)
The salvager was parsing volume IDs just using atoi() and checking if
the result was negative. Since the result is a signed int, this fails
on any volume ID larger than 2^31-1. Change the parser to use strtoul
instead of atoi, and change the check.

While we're here, make a similar change to the DAFS salvageserver,
too.

Change-Id: Icc3377ee507150ff0c53b5bbff6172cb72bca703
Reviewed-on: http://gerrit.openafs.org/4196
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>

src/vol/salvaged.c
src/vol/salvager.c

index 29ecbe3..091636c 100644 (file)
@@ -185,7 +185,8 @@ handleit(struct cmd_syndesc *as, void *arock)
 {
     struct cmd_item *ti;
     char pname[100], *temp;
-    afs_int32 seenpart = 0, seenvol = 0, vid = 0;
+    afs_int32 seenpart = 0, seenvol = 0;
+    VolumeId vid = 0;
     struct cmdline_rock *rock = (struct cmdline_rock *)arock;
 
 #ifdef AFS_SGI_VNODE_GLUE
@@ -272,8 +273,13 @@ handleit(struct cmd_syndesc *as, void *arock)
            strlcpy(pname, ti->data, sizeof(pname));
        }
        if ((ti = as->parms[1].items)) {        /* -volumeid */
+           char *end;
            seenvol = 1;
-           vid = atoi(ti->data);
+           vid = strtoul(ti->data, &end, 10);
+           if (vid == ULONG_MAX || *end != '\0') {
+               printf("Invalid volume id specified; salvage aborted\n");
+               exit(-1);
+           }
        }
 
        if (ShowLog) {
index 1f66406..88d0ec1 100644 (file)
@@ -134,7 +134,8 @@ handleit(struct cmd_syndesc *as, void *arock)
 {
     struct cmd_item *ti;
     char pname[100], *temp;
-    afs_int32 seenpart = 0, seenvol = 0, vid = 0;
+    afs_int32 seenpart = 0, seenvol = 0;
+    VolumeId vid = 0;
     ProgramType pt;
 
 #ifdef FAST_RESTART
@@ -179,13 +180,18 @@ handleit(struct cmd_syndesc *as, void *arock)
        strncpy(pname, ti->data, 100);
     }
     if ((ti = as->parms[1].items)) {   /* -volumeid */
+       char *end;
        if (!seenpart) {
            printf
                ("You must also specify '-partition' option with the '-volumeid' option\n");
            exit(-1);
        }
        seenvol = 1;
-       vid = atoi(ti->data);
+       vid = strtoul(ti->data, &end, 10);
+       if (vid == ULONG_MAX || *end != '\0') {
+           Log("salvage: invalid volume id specified; salvage aborted\n");
+           Exit(1);
+       }
     }
     if (as->parms[2].items)    /* -debug */
        debug = 1;
@@ -347,10 +353,6 @@ handleit(struct cmd_syndesc *as, void *arock)
            SalvageFileSys(partP, 0);
        else {
            /* Salvage individual volume */
-           if (vid <= 0) {
-               Log("salvage: invalid volume id specified; salvage aborted\n");
-               Exit(1);
-           }
            SalvageFileSys(partP, vid);
        }
     }