]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
salvager: Fix volume parsing on 64-bit
authorAndrew Deason <adeason@sinenomine.net>
Wed, 16 Mar 2011 19:44:56 +0000 (14:44 -0500)
committerDerrick Brashear <shadow@dementia.org>
Thu, 24 Mar 2011 16:23:24 +0000 (09:23 -0700)
When an unsigned long is wider than an afs_uint32, comparing the
afs_uint32 vid to ULONG_MAX is always going to be false (which the
compiler can warn us about). Fix this by storing to an unsigned long,
and converting to a volume id after ensuring that the result is not
too large.

(cherry picked from commit ce5e263b488f8cb85662031ee08eea448dab2d27)
Reviewed-on: http://gerrit.openafs.org/4244
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Simon Wilkinson <sxw@inf.ed.ac.uk>
Tested-by: Derrick Brashear <shadow@dementia.org>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Change-Id: Iec2d640daed1e9c175d17823750f272297f890a7
Reviewed-on: http://gerrit.openafs.org/4283
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
src/vol/salvaged.c
src/vol/salvager.c

index ddf4fbe8217f349f1ea90edd204ed93617fb4a81..106d5d3bb963fd40feea0c09bf75edd41a83b2de 100644 (file)
@@ -271,8 +271,15 @@ handleit(struct cmd_syndesc *as, void *arock)
            strlcpy(pname, ti->data, sizeof(pname));
        }
        if ((ti = as->parms[1].items)) {        /* -volumeid */
+           char *end;
+           unsigned long vid_l;
            seenvol = 1;
-           vid = atoi(ti->data);
+           vid_l = strtoul(ti->data, &end, 10);
+           if (vid_l >= MAX_AFS_UINT32 || vid_l == ULONG_MAX || *end != '\0') {
+               printf("Invalid volume id specified; salvage aborted\n");
+               exit(-1);
+           }
+           vid = (VolumeId)vid_l;
        }
 
        if (ShowLog) {
index 6439b0fb3a2006d7249707ed57a93cbdb8d44380..26a82b574e418536964471b3e8d4b0bcca0d00ec 100644 (file)
@@ -180,13 +180,20 @@ handleit(struct cmd_syndesc *as, void *arock)
        strncpy(pname, ti->data, 100);
     }
     if ((ti = as->parms[1].items)) {   /* -volumeid */
+       char *end;
+       unsigned long vid_l;
        if (!seenpart) {
            printf
                ("You must also specify '-partition' option with the '-volumeid' option\n");
            exit(-1);
        }
        seenvol = 1;
-       vid = atoi(ti->data);
+       vid_l = strtoul(ti->data, &end, 10);
+       if (vid_l >= MAX_AFS_UINT32 || vid_l == ULONG_MAX || *end != '\0') {
+           Log("salvage: invalid volume id specified; salvage aborted\n");
+           Exit(1);
+       }
+       vid = (VolumeId)vid_l;
     }
     if (as->parms[2].items)    /* -debug */
        debug = 1;