forked from Mirrors/btrfs-progs
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>master
parent
2e151027d2
commit
6a039e5063
|
@ -126,6 +126,7 @@ static int cmd_add_dev(int argc, char **argv)
|
||||||
goto error_out;
|
goto error_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memset(&ioctl_args, 0, sizeof(ioctl_args));
|
||||||
strncpy_null(ioctl_args.name, path);
|
strncpy_null(ioctl_args.name, path);
|
||||||
res = ioctl(fdmnt, BTRFS_IOC_ADD_DEV, &ioctl_args);
|
res = ioctl(fdmnt, BTRFS_IOC_ADD_DEV, &ioctl_args);
|
||||||
e = errno;
|
e = errno;
|
||||||
|
@ -175,6 +176,7 @@ static int cmd_rm_dev(int argc, char **argv)
|
||||||
ret++;
|
ret++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
memset(&arg, 0, sizeof(arg));
|
||||||
strncpy_null(arg.name, argv[i]);
|
strncpy_null(arg.name, argv[i]);
|
||||||
res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg);
|
res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg);
|
||||||
e = errno;
|
e = errno;
|
||||||
|
@ -312,7 +314,8 @@ static int cmd_ready_dev(int argc, char **argv)
|
||||||
goto out;
|
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);
|
ret = ioctl(fd, BTRFS_IOC_DEVICES_READY, &args);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
fprintf(stderr, "ERROR: unable to determine if the device '%s'"
|
fprintf(stderr, "ERROR: unable to determine if the device '%s'"
|
||||||
|
|
|
@ -1270,6 +1270,7 @@ static int cmd_resize(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Resize '%s' of '%s'\n", path, amount);
|
printf("Resize '%s' of '%s'\n", path, amount);
|
||||||
|
memset(&args, 0, sizeof(args));
|
||||||
strncpy_null(args.name, amount);
|
strncpy_null(args.name, amount);
|
||||||
res = ioctl(fd, BTRFS_IOC_RESIZE, &args);
|
res = ioctl(fd, BTRFS_IOC_RESIZE, &args);
|
||||||
e = errno;
|
e = errno;
|
||||||
|
|
|
@ -357,6 +357,7 @@ again:
|
||||||
printf("Delete subvolume (%s): '%s/%s'\n",
|
printf("Delete subvolume (%s): '%s/%s'\n",
|
||||||
commit_mode == 2 || (commit_mode == 1 && cnt + 1 == argc)
|
commit_mode == 2 || (commit_mode == 1 && cnt + 1 == argc)
|
||||||
? "commit" : "no-commit", dname, vname);
|
? "commit" : "no-commit", dname, vname);
|
||||||
|
memset(&args, 0, sizeof(args));
|
||||||
strncpy_null(args.name, vname);
|
strncpy_null(args.name, vname);
|
||||||
res = ioctl(fd, BTRFS_IOC_SNAP_DESTROY, &args);
|
res = ioctl(fd, BTRFS_IOC_SNAP_DESTROY, &args);
|
||||||
e = errno;
|
e = errno;
|
||||||
|
|
4
utils.c
4
utils.c
|
@ -1409,8 +1409,8 @@ int btrfs_register_one_device(const char *fname)
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
strncpy(args.name, fname, BTRFS_PATH_NAME_MAX);
|
memset(&args, 0, sizeof(args));
|
||||||
args.name[BTRFS_PATH_NAME_MAX-1] = 0;
|
strncpy_null(args.name, fname);
|
||||||
ret = ioctl(fd, BTRFS_IOC_SCAN_DEV, &args);
|
ret = ioctl(fd, BTRFS_IOC_SCAN_DEV, &args);
|
||||||
e = errno;
|
e = errno;
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
|
Loading…
Reference in New Issue