btrfs-progs: convert: fix off-by-one error in overlap test

intersect_with_reserved() currently succeeds if (bytenr + num_bytes) is
greater than or equal to the first address in the range, assuming that
bytenr is also not past the end of the range.

This is wrong. (bytenr + num bytes) is one byte past the last address in
the range we're checking, meaning that our range only overlaps the
reserved range if it's strictly greater than the reserved range's start
address.

For example, imagine a range at 0x3000 with length 0x1000 that we're
checking against a reserved range that starts at 0x4000. The addresses
in our range are 0x3000-0x3fff: it doesn't overlap. But the current
check, (0x3000 + 0x1000 >= 0x4000), will erroneously pass.

Fix the issue by changing >= to >.

Issue: #297
Issue: #349
Author: Thomas Hebb <tommyhebb@gmail.com>
Pull-request: #494
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Thomas Hebb 2022-06-26 15:52:43 -07:00 committed by David Sterba
parent a5f6622d32
commit 407a8721b6
1 changed files with 1 additions and 1 deletions

View File

@ -65,7 +65,7 @@ static u64 intersect_with_reserved(u64 bytenr, u64 num_bytes)
const struct simple_range *range = &btrfs_reserved_ranges[i];
if (bytenr < range_end(range) &&
bytenr + num_bytes >= range->start)
bytenr + num_bytes > range->start)
return range_end(range);
}
return 0;