summaryrefslogtreecommitdiff
path: root/disk-io.c
diff options
context:
space:
mode:
authorQu Wenruo <quwenruo@cn.fujitsu.com>2014-11-12 13:52:11 +0800
committerDavid Sterba <dsterba@suse.cz>2014-11-14 11:02:16 +0100
commit0c44c195fecad7db4bba064e6785faadf5c686b8 (patch)
treedd5d3c5c911f7a7a2918ed2b4deb8c5f56c17674 /disk-io.c
parent1e3da6d65ebdcf83b1d85f11284cde79777277b9 (diff)
downloadbtrfs-progs-0c44c195fecad7db4bba064e6785faadf5c686b8.tar.gz
btrfs-progs: Check sb_bytenr with device size before scanning one device.
When using btrfs check with -s option, if using '-s 2' on a small device which doesn't have the third superblock, "No valid Btrfs found" will be output, but it is not appropriate. So check sb_bytenr against device size before scanning a device and output proper error message. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'disk-io.c')
-rw-r--r--disk-io.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/disk-io.c b/disk-io.c
index e22122c..03edf8e 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -1008,10 +1008,20 @@ int btrfs_scan_fs_devices(int fd, const char *path,
u64 sb_bytenr, int super_recover)
{
u64 total_devs;
+ u64 dev_size;
int ret;
if (!sb_bytenr)
sb_bytenr = BTRFS_SUPER_INFO_OFFSET;
+ dev_size = lseek(fd, 0, SEEK_END);
+ if (dev_size < 0)
+ return (int)(dev_size);
+ lseek(fd, 0, SEEK_SET);
+ if (sb_bytenr > dev_size) {
+ fprintf(stderr, "Superblock bytenr is larger than device size\n");
+ return -EINVAL;
+ }
+
ret = btrfs_scan_one_device(fd, path, fs_devices,
&total_devs, sb_bytenr, super_recover);
if (ret) {