e2fsprogs/tests/f_boundscheck
Darrick J. Wong 203e13cf9c libext2fs: fix bounds check of the bitmap test range in get_free_blocks2
In the loop in ext2fs_get_free_blocks2, we ask the bitmap if there's a
range of free blocks starting at "b" and ending at "b + num - 1".
That quantity is the number of the last block in the range.  Since
ext2fs_blocks_count() returns the number of blocks and not the number
of the last block in the filesystem, the check is incorrect.

Put in a shortcut to exit the loop if finish > start, because in that
case it's obvious that we don't need to reset to the beginning of the
FS to continue the search for blocks.  This is needed to terminate the
loop because the broken test meant that b could get large enough to
equal finish, which would end the while loop.

The attached testcase shows that with the off by one error, it is
possible to throw e2fsck into an infinite loop while it tries to
find space for the inode table even though there's no space for one.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-07-25 07:11:57 -04:00
..
expect.1 libext2fs: fix bounds check of the bitmap test range in get_free_blocks2 2014-07-25 07:11:57 -04:00
expect.2 libext2fs: fix bounds check of the bitmap test range in get_free_blocks2 2014-07-25 07:11:57 -04:00
image.bz2 libext2fs: fix bounds check of the bitmap test range in get_free_blocks2 2014-07-25 07:11:57 -04:00
name libext2fs: fix bounds check of the bitmap test range in get_free_blocks2 2014-07-25 07:11:57 -04:00
script libext2fs: fix bounds check of the bitmap test range in get_free_blocks2 2014-07-25 07:11:57 -04:00