Skip to content

Commit bd96d7b

Browse files
fabio-dChiaHungDuan
authored andcommitted
[scudo] Fix bound checks in MemMap and ReservedMemory methods
Reviewed By: Chia-hungDuan Differential Revision: https://reviews.llvm.org/D152690
1 parent 1ae6a78 commit bd96d7b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ template <class Derived> class MemMapBase {
4141
// want to remap them with different accessibility.
4242
bool remap(uptr Addr, uptr Size, const char *Name, uptr Flags = 0) {
4343
DCHECK(isAllocated());
44-
DCHECK((Addr >= getBase()) || (Addr + Size <= getBase() + getCapacity()));
44+
DCHECK((Addr >= getBase()) && (Addr + Size <= getBase() + getCapacity()));
4545
return invokeImpl(&Derived::remapImpl, Addr, Size, Name, Flags);
4646
}
4747

4848
// This is used to update the pages' access permission. For example, mark
4949
// pages as no read/write permission.
5050
void setMemoryPermission(uptr Addr, uptr Size, uptr Flags) {
5151
DCHECK(isAllocated());
52-
DCHECK((Addr >= getBase()) || (Addr + Size <= getBase() + getCapacity()));
52+
DCHECK((Addr >= getBase()) && (Addr + Size <= getBase() + getCapacity()));
5353
return static_cast<Derived *>(this)->setMemoryPermissionImpl(Addr, Size,
5454
Flags);
5555
}
@@ -59,14 +59,14 @@ template <class Derived> class MemMapBase {
5959
// virtual pages may lead to undefined behavior.
6060
void releasePagesToOS(uptr From, uptr Size) {
6161
DCHECK(isAllocated());
62-
DCHECK((From >= getBase()) || (From + Size <= getBase() + getCapacity()));
62+
DCHECK((From >= getBase()) && (From + Size <= getBase() + getCapacity()));
6363
invokeImpl(&Derived::releasePagesToOSImpl, From, Size);
6464
}
6565
// This is similar to the above one except that any subsequent access to the
6666
// released pages will return with zero-filled pages.
6767
void releaseAndZeroPagesToOS(uptr From, uptr Size) {
6868
DCHECK(isAllocated());
69-
DCHECK((From >= getBase()) || (From + Size <= getBase() + getCapacity()));
69+
DCHECK((From >= getBase()) && (From + Size <= getBase() + getCapacity()));
7070
invokeImpl(&Derived::releaseAndZeroPagesToOSImpl, From, Size);
7171
}
7272

@@ -109,7 +109,7 @@ template <class Derived, typename MemMapTy> class ReservedMemory {
109109
// the reserved pages is managed by each implementation.
110110
MemMapT dispatch(uptr Addr, uptr Size) {
111111
DCHECK(isCreated());
112-
DCHECK((Addr >= getBase()) || (Addr + Size <= getBase() + getCapacity()));
112+
DCHECK((Addr >= getBase()) && (Addr + Size <= getBase() + getCapacity()));
113113
return invokeImpl(&Derived::dispatchImpl, Addr, Size);
114114
}
115115

0 commit comments

Comments
 (0)