From 4cce2094b18ab674c707d5c9f747d71874076d2c Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Wed, 23 Jan 2013 15:11:24 -0800 Subject: [PATCH] btrfs-progs: don't leak fd in resize Argument validation failed to close the fd that was opened. So check the arguments before opening anything. Signed-off-by: Zach Brown --- cmds-filesystem.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index 507239ad..045c896f 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -464,11 +464,6 @@ static int cmd_resize(int argc, char **argv) amount = argv[1]; path = argv[2]; - fd = open_file_or_dir(path); - if (fd < 0) { - fprintf(stderr, "ERROR: can't access to '%s'\n", path); - return 12; - } len = strlen(amount); if (len == 0 || len >= BTRFS_VOL_NAME_MAX) { fprintf(stderr, "ERROR: size value too long ('%s)\n", @@ -476,6 +471,12 @@ static int cmd_resize(int argc, char **argv) return 14; } + fd = open_file_or_dir(path); + if (fd < 0) { + fprintf(stderr, "ERROR: can't access to '%s'\n", path); + return 12; + } + printf("Resize '%s' of '%s'\n", path, amount); strncpy(args.name, amount, BTRFS_PATH_NAME_MAX); args.name[BTRFS_PATH_NAME_MAX-1] = 0;