From: Andrew Price Date: Mon, 19 May 2014 15:47:58 +0100 Subject: [Cluster-devel] [PATCH] gfs2_edit: Fix parsing the savemeta -z option Message-ID: <1400510878-17983-1-git-send-email-anprice@redhat.com> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Specifying -z0 instead of -z 0 could confuse gfs2_edit to the point where it would call ftruncate on the filesystem instead of the output file. Fix up the -z parsing function to recognise when the space is omitted and avoid calling ftruncate on the wrong file. Signed-off-by: Andrew Price --- gfs2/edit/hexedit.c | 26 ++++++++++++++++---------- tests/edit.at | 7 +++++++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c index 53a816d..0982f7b 100644 --- a/gfs2/edit/hexedit.c +++ b/gfs2/edit/hexedit.c @@ -2608,19 +2608,25 @@ static void usage(void) */ static void getgziplevel(char *argv[], int *i) { + char *opt, *arg; char *endptr; - (*i)++; - if (!strcasecmp(argv[*i], "-z")) { - (*i)++; - errno = 0; - gziplevel = strtol(argv[*i], &endptr, 10); - if (errno || endptr == argv[*i] || gziplevel < 0 || gziplevel > 9) { - fprintf(stderr, "Compression level out of range: %s\n", argv[*i]); - exit(-1); - } + + arg = argv[1 + *i]; + if (strncmp(arg, "-z", 2)) { + return; + } else if (arg[2] != '\0') { + opt = &arg[2]; } else { - (*i)--; + (*i)++; + opt = argv[1 + *i]; + } + errno = 0; + gziplevel = strtol(opt, &endptr, 10); + if (errno || endptr == opt || gziplevel < 0 || gziplevel > 9) { + fprintf(stderr, "Compression level out of range: %s\n", opt); + exit(-1); } + (*i)++; } /* ------------------------------------------------------------------------ */ diff --git a/tests/edit.at b/tests/edit.at index 3428d64..e2a702c 100644 --- a/tests/edit.at +++ b/tests/edit.at @@ -11,5 +11,12 @@ Reading resource groups...Done. File system size: 4.1023GB GFS_TGT_REGEN AT_CHECK([gfs2_edit restoremeta test.meta $GFS_TGT], 0, [ignore], [ignore]) AT_CHECK([fsck.gfs2 -n $GFS_TGT], 0, [ignore], [ignore]) +AT_CLEANUP +AT_SETUP([Savemeta/restoremeta, no compression]) +GFS_TGT_REGEN +AT_CHECK([$GFS_MKFS -p lock_nolock $GFS_TGT $(($(gfs_max_blocks 4096)/2))], 0, [ignore], [ignore]) +AT_CHECK([gfs2_edit savemeta -z0 $GFS_TGT test.meta], 0, [ignore], [ignore]) +AT_CHECK([gfs2_edit restoremeta test.meta $GFS_TGT], 0, [ignore], [ignore]) +AT_CHECK([fsck.gfs2 -n $GFS_TGT], 0, [ignore], [ignore]) AT_CLEANUP -- 1.9.0