From: Theodore Ts'o Date: Tue, 9 Aug 2022 01:02:51 +0000 (-0400) Subject: libext2fs: make sure the bitmap locations are valid when writing bitmaps X-Git-Tag: v1.46.6-rc1~40 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b770b0fe7e2564afd95f2008533c6db435e74456;p=thirdparty%2Fe2fsprogs.git libext2fs: make sure the bitmap locations are valid when writing bitmaps Signed-off-by: Theodore Ts'o --- diff --git a/lib/ext2fs/rw_bitmaps.c b/lib/ext2fs/rw_bitmaps.c index 7be4a55ab..1fe65f744 100644 --- a/lib/ext2fs/rw_bitmaps.c +++ b/lib/ext2fs/rw_bitmaps.c @@ -119,7 +119,7 @@ static errcode_t write_bitmaps(ext2_filsys fs, int do_inode, int do_block) fs->flags |= EXT2_FLAG_DIRTY; blk = ext2fs_block_bitmap_loc(fs, i); - if (blk) { + if (blk && blk < ext2fs_blocks_count(fs->super)) { retval = io_channel_write_blk64(fs->io, blk, 1, block_buf); if (retval) { @@ -151,7 +151,7 @@ static errcode_t write_bitmaps(ext2_filsys fs, int do_inode, int do_block) fs->flags |= EXT2_FLAG_DIRTY; blk = ext2fs_inode_bitmap_loc(fs, i); - if (blk) { + if (blk && blk < ext2fs_blocks_count(fs->super)) { retval = io_channel_write_blk64(fs->io, blk, 1, inode_buf); if (retval) { @@ -204,14 +204,14 @@ static errcode_t mark_uninit_bg_group_blocks(ext2_filsys fs) * Mark block used for the block bitmap */ blk = ext2fs_block_bitmap_loc(fs, i); - if (blk) + if (blk && blk < ext2fs_blocks_count(fs->super)) ext2fs_mark_block_bitmap2(bmap, blk); /* * Mark block used for the inode bitmap */ blk = ext2fs_inode_bitmap_loc(fs, i); - if (blk) + if (blk && blk < ext2fs_blocks_count(fs->super)) ext2fs_mark_block_bitmap2(bmap, blk); } return 0;