[compiler-rt] bd96d7b - [scudo] Fix bound checks in MemMap and ReservedMemory methods

Chia-hung Duan via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 13 20:56:46 PDT 2023


Author: Fabio D'Urso
Date: 2023-06-14T03:55:54Z
New Revision: bd96d7b81f457c16d3bced596ab3cf095f8fb101

URL: https://github.com/llvm/llvm-project/commit/bd96d7b81f457c16d3bced596ab3cf095f8fb101
DIFF: https://github.com/llvm/llvm-project/commit/bd96d7b81f457c16d3bced596ab3cf095f8fb101.diff

LOG: [scudo] Fix bound checks in MemMap and ReservedMemory methods

Reviewed By: Chia-hungDuan

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/scudo/standalone/mem_map_base.h b/compiler-rt/lib/scudo/standalone/mem_map_base.h
index 0560f4102d860..8f06a523fb4d8 100644
--- a/compiler-rt/lib/scudo/standalone/mem_map_base.h
+++ b/compiler-rt/lib/scudo/standalone/mem_map_base.h
@@ -41,7 +41,7 @@ template <class Derived> class MemMapBase {
   // want to remap them with 
diff erent 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 @@ template <class Derived> class MemMapBase {
   // 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 @@ template <class Derived> class MemMapBase {
   // 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 @@ template <class Derived, typename MemMapTy> class ReservedMemory {
   // 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);
   }
 


        


More information about the llvm-commits mailing list