Skip to content

Commit

Permalink
udev: modernize udev-builtin-btrfs a bit
Browse files Browse the repository at this point in the history
Let's in particular log an even if a device name is too long for the
btrfs ioctl structure, instead of truncating it (which could
theoretically reference a different device).
  • Loading branch information
poettering committed Feb 26, 2025
1 parent f36b0ec commit eee0564
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/udev/udev-builtin-btrfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@

static int builtin_btrfs(UdevEvent *event, int argc, char *argv[]) {
sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
struct btrfs_ioctl_vol_args args = {};
_cleanup_close_ int fd = -EBADF;
int r;

if (argc != 3 || !streq(argv[1], "ready"))
return log_device_error_errno(dev, SYNTHETIC_ERRNO(EINVAL), "Invalid arguments");

fd = open("/dev/btrfs-control", O_RDWR|O_CLOEXEC|O_NOCTTY);
_cleanup_close_ int fd = open("/dev/btrfs-control", O_RDWR|O_CLOEXEC|O_NOCTTY);
if (fd < 0) {
if (ERRNO_IS_DEVICE_ABSENT(errno)) {
/* Driver not installed? Then we aren't ready. This is useful in initrds that lack
Expand All @@ -34,7 +32,11 @@ static int builtin_btrfs(UdevEvent *event, int argc, char *argv[]) {
return log_device_debug_errno(dev, errno, "Failed to open /dev/btrfs-control: %m");
}

strscpy(args.name, sizeof(args.name), argv[2]);
struct btrfs_ioctl_vol_args args = {};
if (strlen(argv[2]) >= sizeof(args.name))
return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL), "Device name too long for BTRFS_IOC_DEVICES_READY call: %s", argv[2]);

strncpy(args.name, argv[2], sizeof(args.name));
r = ioctl(fd, BTRFS_IOC_DEVICES_READY, &args);
if (r < 0)
return log_device_debug_errno(dev, errno, "Failed to call BTRFS_IOC_DEVICES_READY: %m");
Expand Down

0 comments on commit eee0564

Please sign in to comment.