[Ocfs2-tools-devel] [PATCH] Correct range check of ocfs2_read_backup_super()
Goldwyn Rodrigues
rgoldwyn at gmail.com
Wed Jul 13 08:10:27 PDT 2011
debugfs.ocfs2 is unable to access the backup at block[0] of the offset array.
This is because of the incorrect range check and evaluation of block offset.
Correct the range check and usage of the function.
Not sure if I am changing the convention on how you perceive the block indexes
here though. In any case, I am following the fsck.ocfs2 user interface
[1,sbnum], and internally [0,sbnum).
Signed-off-by: Goldwyn Rodrigues
---
diff --git a/debugfs.ocfs2/commands.c b/debugfs.ocfs2/commands.c
index 663164f..e2daa11 100644
--- a/debugfs.ocfs2/commands.c
+++ b/debugfs.ocfs2/commands.c
@@ -1005,7 +1005,7 @@ static void do_stats (char **args)
if (!sb_num)
in = gbls.fs->fs_super;
else {
- ret = ocfs2_read_backup_super(gbls.fs, sb_num, buf);
+ ret = ocfs2_read_backup_super(gbls.fs, sb_num - 1, buf);
if (ret) {
com_err(gbls.cmd, ret, "while reading backup "
"superblock");
diff --git a/libocfs2/backup_super.c b/libocfs2/backup_super.c
index 4de1699..3fb026e 100644
--- a/libocfs2/backup_super.c
+++ b/libocfs2/backup_super.c
@@ -198,7 +198,7 @@ errcode_t ocfs2_read_backup_super(ocfs2_filesys
*fs, int backup, char *sbbuf)
numsb = ocfs2_get_backup_super_offsets(fs, blocks,
ARRAY_SIZE(blocks));
- if (backup < 1 || backup > numsb)
+ if (backup < 0 || backup >= numsb)
return OCFS2_ET_NO_BACKUP_SUPER;
return ocfs2_read_super(fs, blocks[backup], sbbuf);
--
Goldwyn
More information about the Ocfs2-tools-devel
mailing list