mirror of
https://github.com/chromium/crashpad.git
synced 2025-03-09 14:06:33 +00:00
posix: DCHECK for (addr + len) overflow in ScopedMmap::ResetAddrLen()
This also enhances ScopedMmapDeathTest.Mprotect to better ensure that ScopedMmap::Mprotect() works properly. Bug: crashpad:30 Test: crashpad_util_test ScopedMmap*.* Change-Id: Iff35dba9fa993086f3f4cd8f4a862d802e637bb1 Reviewed-on: https://chromium-review.googlesource.com/464547 Reviewed-by: Joshua Peraza <jperaza@chromium.org>
This commit is contained in:
parent
aa2bc55777
commit
385fe6615f
@ -19,6 +19,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/numerics/safe_math.h"
|
||||
|
||||
namespace {
|
||||
|
||||
@ -56,6 +57,7 @@ bool ScopedMmap::ResetAddrLen(void* addr, size_t len) {
|
||||
DCHECK_NE(len, 0u);
|
||||
DCHECK_EQ(new_addr % getpagesize(), 0u);
|
||||
DCHECK_EQ(len % getpagesize(), 0u);
|
||||
DCHECK((base::CheckedNumeric<uintptr_t>(new_addr) + (len - 1)).IsValid());
|
||||
}
|
||||
|
||||
bool result = true;
|
||||
|
@ -302,11 +302,15 @@ TEST(ScopedMmapDeathTest, Mprotect) {
|
||||
EXPECT_EQ(kPageSize, mapping.len());
|
||||
|
||||
char* addr = mapping.addr_as<char*>();
|
||||
*addr = 0;
|
||||
*addr = 1;
|
||||
|
||||
ASSERT_TRUE(mapping.Mprotect(PROT_READ));
|
||||
|
||||
EXPECT_DEATH(*addr = 0, "");
|
||||
|
||||
ASSERT_TRUE(mapping.Mprotect(PROT_READ | PROT_WRITE));
|
||||
EXPECT_EQ(1, *addr);
|
||||
*addr = 2;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
Loading…
x
Reference in New Issue
Block a user