From 0884e9d0fddf2be81abf6468209048331efa8a1e Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Thu, 10 Mar 2011 14:55:50 -0600 Subject: [PATCH] salvager: Do not abort on large volume IDs 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 Reviewed-by: Derrick Brashear --- src/vol/salvaged.c | 10 ++++++++-- src/vol/salvager.c | 14 ++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/vol/salvaged.c b/src/vol/salvaged.c index 29ecbe3..091636c 100644 --- a/src/vol/salvaged.c +++ b/src/vol/salvaged.c @@ -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) { diff --git a/src/vol/salvager.c b/src/vol/salvager.c index 1f66406..88d0ec1 100644 --- a/src/vol/salvager.c +++ b/src/vol/salvager.c @@ -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); } } -- 1.9.4