Project

General

Profile

Bug #522 ยป diff.txt

Valerii Huhnin, 12/27/2023 07:01 PM

 
diff --git a/src/commonlib/include/commonlib/region.h b/src/commonlib/include/commonlib/region.h
index 25efcc8724..a92ad168fd 100644
--- a/src/commonlib/include/commonlib/region.h
+++ b/src/commonlib/include/commonlib/region.h
@@ -119,8 +119,15 @@ static inline size_t region_end(const struct region *r)
static inline bool region_overlap(const struct region *r1, const struct region *r2)
{
- return (region_end(r1) > region_offset(r2)) &&
- (region_offset(r1) < region_end(r2));
+ if (region_sz(r1) == 0 || region_sz(r2) == 0) {
+ return false;
+ }
+
+ size_t size1 = min(region_sz(r1) - 1, (size_t)SIZE_MAX - region_offset(r1));
+ size_t size2 = min(region_sz(r2) - 1, (size_t)SIZE_MAX - region_offset(r2));
+
+ return (region_offset(r1) + size1 >= region_offset(r2)) &&
+ (region_offset(r1) <= size2 + region_offset(r2));
}
static inline const struct region *region_device_region(
    (1-1/1)