Commit 99ba55ad696944b37d5557bc5b4816890854fdb9

Authored by Stefan Behrens
Committed by David Sterba
1 parent b9688bb845

Btrfs: fix btrfs_ioctl_dev_info() crash on missing device

When a filesystem is mounted with the degraded option, it is
possible that some of the devices are not there.
btrfs_ioctl_dev_info() crashs in this case because the device
name is a NULL pointer. This ioctl was only used for scrub.

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>

Showing 1 changed file with 4 additions and 1 deletions Side-by-side Diff

... ... @@ -2262,7 +2262,10 @@
2262 2262 di_args->bytes_used = dev->bytes_used;
2263 2263 di_args->total_bytes = dev->total_bytes;
2264 2264 memcpy(di_args->uuid, dev->uuid, sizeof(di_args->uuid));
2265   - strncpy(di_args->path, dev->name, sizeof(di_args->path));
  2265 + if (dev->name)
  2266 + strncpy(di_args->path, dev->name, sizeof(di_args->path));
  2267 + else
  2268 + di_args->path[0] = '\0';
2266 2269  
2267 2270 out:
2268 2271 if (ret == 0 && copy_to_user(arg, di_args, sizeof(*di_args)))