aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2022-08-08 21:02:51 -0400
committerTheodore Ts'o <tytso@mit.edu>2022-08-08 21:02:51 -0400
commitb770b0fe7e2564afd95f2008533c6db435e74456 (patch)
tree341b07196ab880e0ebbc4eb9e9c99cca04b625e0
parent95d4ab9917cf1503b9c56acac98633efe89d48e5 (diff)
downloade2fsprogs-b770b0fe7e2564afd95f2008533c6db435e74456.tar.gz
libext2fs: make sure the bitmap locations are valid when writing bitmaps
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r--lib/ext2fs/rw_bitmaps.c8
1 files changed, 4 insertions, 4 deletions
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;