From b770b0fe7e2564afd95f2008533c6db435e74456 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Mon, 8 Aug 2022 21:02:51 -0400 Subject: [PATCH] libext2fs: make sure the bitmap locations are valid when writing bitmaps Signed-off-by: Theodore Ts'o --- lib/ext2fs/rw_bitmaps.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ext2fs/rw_bitmaps.c b/lib/ext2fs/rw_bitmaps.c index 7be4a55..1fe65f7 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; -- 1.8.3.1