aboutsummaryrefslogtreecommitdiffstats
path: root/cmds-device.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.cz>2015-06-12 14:36:51 +0200
committerDavid Sterba <dsterba@suse.cz>2015-06-12 16:44:48 +0200
commit6a039e5063fc96cc72a0a0b2bdc97403fb080de1 (patch)
tree162acdd186f1c1bbdba875ebf470f33a67f691e1 /cmds-device.c
parent2e151027d245a762326dac8e814db9fc59113454 (diff)
downloadbtrfs-progs-6a039e5063fc96cc72a0a0b2bdc97403fb080de1.tar.gz
btrfs-progs-6a039e5063fc96cc72a0a0b2bdc97403fb080de1.tar.xz
btrfs-progs-6a039e5063fc96cc72a0a0b2bdc97403fb080de1.zip
btrfs-progs: properly set up ioctl arguments
At some places we do not clear the whole ioctl structure and could pass garbage to kernel. Zero the ioctl vol_args and use a helper for copying the path. Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'cmds-device.c')
-rw-r--r--cmds-device.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/cmds-device.c b/cmds-device.c
index 3a10438..c588a6e 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -126,6 +126,7 @@ static int cmd_add_dev(int argc, char **argv)
goto error_out;
}
+ memset(&ioctl_args, 0, sizeof(ioctl_args));
strncpy_null(ioctl_args.name, path);
res = ioctl(fdmnt, BTRFS_IOC_ADD_DEV, &ioctl_args);
e = errno;
@@ -175,6 +176,7 @@ static int cmd_rm_dev(int argc, char **argv)
ret++;
continue;
}
+ memset(&arg, 0, sizeof(arg));
strncpy_null(arg.name, argv[i]);
res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg);
e = errno;
@@ -312,7 +314,8 @@ static int cmd_ready_dev(int argc, char **argv)
goto out;
}
- strncpy(args.name, path, BTRFS_PATH_NAME_MAX);
+ memset(&args, 0, sizeof(args));
+ strncpy_null(args.name, path);
ret = ioctl(fd, BTRFS_IOC_DEVICES_READY, &args);
if (ret < 0) {
fprintf(stderr, "ERROR: unable to determine if the device '%s'"