Index: lib/asan/asan_allocator.cc =================================================================== --- lib/asan/asan_allocator.cc +++ lib/asan/asan_allocator.cc @@ -839,6 +839,10 @@ void *asan_pvalloc(uptr size, BufferedStackTrace *stack) { uptr PageSize = GetPageSizeCached(); + if (UNLIKELY(CheckForPvallocOverflow(size, PageSize))) { + errno = errno_ENOMEM; + return AsanAllocator::FailureHandler::OnBadRequest(); + } // pvalloc(0) should allocate one page. size = size ? RoundUpTo(size, PageSize) : PageSize; return SetErrnoOnNull( Index: lib/asan/tests/asan_test.cc =================================================================== --- lib/asan/tests/asan_test.cc +++ lib/asan/tests/asan_test.cc @@ -140,6 +140,12 @@ EXPECT_EQ(0U, (uintptr_t)a % kPageSize); a[101] = 1; // we should not report an error here. free(a); + + // Overflows should be caught. + EXPECT_DEATH(a = (char *)pvalloc((uintptr_t)-(kPageSize - 1)), + "allocator is terminating the process instead of returning 0"); + EXPECT_DEATH(a = (char *)pvalloc((uintptr_t)-1), + "allocator is terminating the process instead of returning 0"); } #endif // SANITIZER_TEST_HAS_PVALLOC