]> granicus.if.org Git - llvm/commitdiff
[libFuzzer] Fix OutOfMemory tests to work on 32 bits.
authorMarcos Pividori <mpividori@google.com>
Sun, 22 Jan 2017 01:58:50 +0000 (01:58 +0000)
committerMarcos Pividori <mpividori@google.com>
Sun, 22 Jan 2017 01:58:50 +0000 (01:58 +0000)
I add 2 changes to make the tests work on 32 bits and on 64 bits.
I change the size allocated to 0x20000000 and add the flag: -rss_limit_mb=300.
Otherwise the output for 32 bits and 64 bits is different.
For 64 bits the value 0xff000000 doesn't exceed kMaxAllowedMallocSize.
For 32 bits, kMaxAllowedMallocSize is set to 0xc0000000, so the call to
Allocate() will fail earlier printing "WARNING: AddressSanitizer failed to
allocate ..." , and wont't call malloc hooks.
So, we need to consider a size smaller than 2GB (so malloc doesn't fail on
32bits) and greater that the value provided by -rss_limit_mb.
Because of that I use: 0x20000000.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292744 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Fuzzer/test/OutOfMemorySingleLargeMallocTest.cpp
lib/Fuzzer/test/fuzzer-oom.test

index ea23a601aa2320309a01587ed611b6569912eb4e..316b7682b8e60ca1148f16636ee24aca0d7f377c 100644 (file)
@@ -15,7 +15,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
   if (Size > 0 && Data[0] == 'H') {
     if (Size > 1 && Data[1] == 'i') {
       if (Size > 2 && Data[2] == '!') {
-          size_t kSize = 0xff000000U;
+          size_t kSize = 0x20000000U;
           char *p = new char[kSize];
           SinkPtr = p;
           delete [] p;
index 8caf649e9f046aa7325efa5565417b43e95ad2f1..5c3bf78158a0c9a4e308acf68ae3a655b076d037 100644 (file)
@@ -3,8 +3,8 @@ CHECK: ERROR: libFuzzer: out-of-memory (used: {{.*}}; limit: 300Mb)
 CHECK: Test unit written to ./oom-
 SUMMARY: libFuzzer: out-of-memory
 
-RUN: not LLVMFuzzer-OutOfMemorySingleLargeMallocTest 2>&1 | FileCheck %s --check-prefix=SINGLE_LARGE_MALLOC
-SINGLE_LARGE_MALLOC: libFuzzer: out-of-memory (malloc(42{{.*}}))
+RUN: not LLVMFuzzer-OutOfMemorySingleLargeMallocTest -rss_limit_mb=300 2>&1 | FileCheck %s --check-prefix=SINGLE_LARGE_MALLOC
+SINGLE_LARGE_MALLOC: libFuzzer: out-of-memory (malloc(53{{.*}}))
 SINGLE_LARGE_MALLOC: in LLVMFuzzerTestOneInput
 
 # Check that -rss_limit_mb=0 means no limit.