From 6a039e5063fc96cc72a0a0b2bdc97403fb080de1 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 12 Jun 2015 14:36:51 +0200 Subject: 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 --- cmds-device.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'cmds-device.c') diff --git a/cmds-device.c b/cmds-device.c index 3a10438b..c588a6e0 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'" -- cgit v1.2.3