mirror of
https://github.com/kdave/btrfs-progs
synced 2025-02-17 02:06:51 +00:00
btrfs-progs: use correct type for device id iteration in get_fs_info
Coverity reports (CID 1374096) that there's return value overflow of ret from get_device_info, but this most likely cannot happen. There's another minor issue where we use int to iterate over devids. Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
92847b5cd6
commit
c29fea4344
17
utils.c
17
utils.c
@ -3084,7 +3084,7 @@ int get_fs_info(const char *path, struct btrfs_ioctl_fs_info_args *fi_args,
|
|||||||
int fd = -1;
|
int fd = -1;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int ndevs = 0;
|
int ndevs = 0;
|
||||||
int i = 0;
|
u64 last_devid = 0;
|
||||||
int replacing = 0;
|
int replacing = 0;
|
||||||
struct btrfs_fs_devices *fs_devices_mnt = NULL;
|
struct btrfs_fs_devices *fs_devices_mnt = NULL;
|
||||||
struct btrfs_ioctl_dev_info_args *di_args;
|
struct btrfs_ioctl_dev_info_args *di_args;
|
||||||
@ -3097,7 +3097,6 @@ int get_fs_info(const char *path, struct btrfs_ioctl_fs_info_args *fi_args,
|
|||||||
if (is_block_device(path) == 1) {
|
if (is_block_device(path) == 1) {
|
||||||
struct btrfs_super_block *disk_super;
|
struct btrfs_super_block *disk_super;
|
||||||
char buf[BTRFS_SUPER_INFO_SIZE];
|
char buf[BTRFS_SUPER_INFO_SIZE];
|
||||||
u64 devid;
|
|
||||||
|
|
||||||
/* Ensure it's mounted, then set path to the mountpoint */
|
/* Ensure it's mounted, then set path to the mountpoint */
|
||||||
fd = open(path, O_RDONLY);
|
fd = open(path, O_RDONLY);
|
||||||
@ -3125,10 +3124,8 @@ int get_fs_info(const char *path, struct btrfs_ioctl_fs_info_args *fi_args,
|
|||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
devid = btrfs_stack_device_id(&disk_super->dev_item);
|
last_devid = btrfs_stack_device_id(&disk_super->dev_item);
|
||||||
|
fi_args->max_id = last_devid;
|
||||||
fi_args->max_id = devid;
|
|
||||||
i = devid;
|
|
||||||
|
|
||||||
memcpy(fi_args->fsid, fs_devices_mnt->fsid, BTRFS_FSID_SIZE);
|
memcpy(fi_args->fsid, fs_devices_mnt->fsid, BTRFS_FSID_SIZE);
|
||||||
close(fd);
|
close(fd);
|
||||||
@ -3165,8 +3162,8 @@ int get_fs_info(const char *path, struct btrfs_ioctl_fs_info_args *fi_args,
|
|||||||
fi_args->num_devices++;
|
fi_args->num_devices++;
|
||||||
ndevs++;
|
ndevs++;
|
||||||
replacing = 1;
|
replacing = 1;
|
||||||
if (i == 0)
|
if (last_devid == 0)
|
||||||
i++;
|
last_devid++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3181,8 +3178,8 @@ int get_fs_info(const char *path, struct btrfs_ioctl_fs_info_args *fi_args,
|
|||||||
|
|
||||||
if (replacing)
|
if (replacing)
|
||||||
memcpy(di_args, &tmp, sizeof(tmp));
|
memcpy(di_args, &tmp, sizeof(tmp));
|
||||||
for (; i <= fi_args->max_id; ++i) {
|
for (; last_devid <= fi_args->max_id; last_devid++) {
|
||||||
ret = get_device_info(fd, i, &di_args[ndevs]);
|
ret = get_device_info(fd, last_devid, &di_args[ndevs]);
|
||||||
if (ret == -ENODEV)
|
if (ret == -ENODEV)
|
||||||
continue;
|
continue;
|
||||||
if (ret)
|
if (ret)
|
||||||
|
Loading…
Reference in New Issue
Block a user