[scudo] Fix bound checks in MemMap and ReservedMemory methods
authorFabio D'Urso <fdurso@google.com>
Wed, 14 Jun 2023 03:54:08 +0000 (03:54 +0000)
committerChia-hung Duan <chiahungduan@google.com>
Wed, 14 Jun 2023 03:55:54 +0000 (03:55 +0000)
Reviewed By: Chia-hungDuan

Differential Revision: https://reviews.llvm.org/D152690

compiler-rt/lib/scudo/standalone/mem_map_base.h

index 0560f41..8f06a52 100644 (file)
@@ -41,7 +41,7 @@ public:
   // want to remap them with different accessibility.
   bool remap(uptr Addr, uptr Size, const char *Name, uptr Flags = 0) {
     DCHECK(isAllocated());
-    DCHECK((Addr >= getBase()) || (Addr + Size <= getBase() + getCapacity()));
+    DCHECK((Addr >= getBase()) && (Addr + Size <= getBase() + getCapacity()));
     return invokeImpl(&Derived::remapImpl, Addr, Size, Name, Flags);
   }
 
@@ -49,7 +49,7 @@ public:
   // pages as no read/write permission.
   void setMemoryPermission(uptr Addr, uptr Size, uptr Flags) {
     DCHECK(isAllocated());
-    DCHECK((Addr >= getBase()) || (Addr + Size <= getBase() + getCapacity()));
+    DCHECK((Addr >= getBase()) && (Addr + Size <= getBase() + getCapacity()));
     return static_cast<Derived *>(this)->setMemoryPermissionImpl(Addr, Size,
                                                                  Flags);
   }
@@ -59,14 +59,14 @@ public:
   // virtual pages may lead to undefined behavior.
   void releasePagesToOS(uptr From, uptr Size) {
     DCHECK(isAllocated());
-    DCHECK((From >= getBase()) || (From + Size <= getBase() + getCapacity()));
+    DCHECK((From >= getBase()) && (From + Size <= getBase() + getCapacity()));
     invokeImpl(&Derived::releasePagesToOSImpl, From, Size);
   }
   // This is similar to the above one except that any subsequent access to the
   // released pages will return with zero-filled pages.
   void releaseAndZeroPagesToOS(uptr From, uptr Size) {
     DCHECK(isAllocated());
-    DCHECK((From >= getBase()) || (From + Size <= getBase() + getCapacity()));
+    DCHECK((From >= getBase()) && (From + Size <= getBase() + getCapacity()));
     invokeImpl(&Derived::releaseAndZeroPagesToOSImpl, From, Size);
   }
 
@@ -109,7 +109,7 @@ public:
   // the reserved pages is managed by each implementation.
   MemMapT dispatch(uptr Addr, uptr Size) {
     DCHECK(isCreated());
-    DCHECK((Addr >= getBase()) || (Addr + Size <= getBase() + getCapacity()));
+    DCHECK((Addr >= getBase()) && (Addr + Size <= getBase() + getCapacity()));
     return invokeImpl(&Derived::dispatchImpl, Addr, Size);
   }