From 4faba5b2aebb89619f5798274394670cce96370c Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Tue, 16 Jun 1998 05:23:41 +0000 Subject: [PATCH] ChangeLog, read_bb.c: Make ext2fs_read_bb_inode more robust against a completely trashed bad block inode. --- lib/ext2fs/ChangeLog | 5 +++++ lib/ext2fs/read_bb.c | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog index b8675fa..ccb74d4 100644 --- a/lib/ext2fs/ChangeLog +++ b/lib/ext2fs/ChangeLog @@ -1,3 +1,8 @@ +1998-06-16 Theodore Ts'o + + * read_bb.c (ext2fs_read_bb_inode): Make function more robust + against a completely trashed bad block inode. + 1998-06-10 Theodore Ts'o * alloc_tables.c (ext2fs_allocate_group_table): Fix bug so that if diff --git a/lib/ext2fs/read_bb.c b/lib/ext2fs/read_bb.c index c005d42..85c8613 100644 --- a/lib/ext2fs/read_bb.c +++ b/lib/ext2fs/read_bb.c @@ -51,6 +51,10 @@ static int mark_bad_block(ext2_filsys fs, blk_t *block_nr, if (blockcnt < 0) return 0; + if ((*block_nr < fs->super->s_first_data_block) || + (*block_nr >= fs->super->s_blocks_count)) + return 0; /* Ignore illegal blocks */ + rb->err = ext2fs_badblocks_list_add(rb->bb_list, *block_nr); if (rb->err) return BLOCK_ABORT; @@ -73,7 +77,11 @@ errcode_t ext2fs_read_bb_inode(ext2_filsys fs, ext2_badblocks_list *bb_list) retval = ext2fs_read_inode(fs, EXT2_BAD_INO, &inode); if (retval) return retval; - numblocks = (inode.i_blocks / (fs->blocksize / 512)) + 20; + if (inode.i_blocks < 500) + numblocks = (inode.i_blocks / + (fs->blocksize / 512)) + 20; + else + numblocks = 500; retval = ext2fs_badblocks_list_create(bb_list, numblocks); if (retval) return retval; -- 1.8.3.1