[syslinux:master] btrfs: do not read past the end of the disk

syslinux-bot for H. Peter Anvin hpa at zytor.com
Fri Jun 25 20:36:02 PDT 2010


Commit-ID:  1d166293d94464422ad788c1d57684f69da1c328
Gitweb:     http://syslinux.zytor.com/commit/1d166293d94464422ad788c1d57684f69da1c328
Author:     H. Peter Anvin <hpa at zytor.com>
AuthorDate: Fri, 25 Jun 2010 20:10:09 -0700
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Fri, 25 Jun 2010 20:10:09 -0700

btrfs: do not read past the end of the disk

When looking for the current superblock, don't read past the end of
the disk.  This more or less assumes that the superblocks are
reasonably consistent with regards to the total filesystem size.

Signed-off-by: H. Peter Anvin <hpa at zytor.com>


---
 core/fs/btrfs/btrfs.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/core/fs/btrfs/btrfs.c b/core/fs/btrfs/btrfs.c
index 72dcbe9..41e301a 100644
--- a/core/fs/btrfs/btrfs.c
+++ b/core/fs/btrfs/btrfs.c
@@ -11,6 +11,7 @@
  *
  */
 
+#include <dprintf.h>
 #include <stdio.h>
 #include <string.h>
 #include <cache.h>
@@ -207,9 +208,16 @@ static void btrfs_read_super_block(struct fs_info *fs)
 	u64 transid = 0;
 	struct btrfs_super_block buf;
 
+	sb.total_bytes = ~0;	/* Unknown as of yet */
+
 	/* find most recent super block */
 	for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) {
 		offset = btrfs_sb_offset(i);
+		dprintf("btrfs super: %llu max %llu\n",
+			offset, sb.total_bytes);
+		if (offset >= sb.total_bytes)
+			break;
+
 		ret = btrfs_read(fs, (char *)&buf, offset, sizeof(buf));
 		if (ret < sizeof(buf))
 			break;



More information about the Syslinux-commits mailing list