[llvm] r292744 - [libFuzzer] Fix OutOfMemory tests to work on 32 bits.

Marcos Pividori via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 21 17:58:51 PST 2017


Author: mpividori
Date: Sat Jan 21 19:58:50 2017
New Revision: 292744

URL: http://llvm.org/viewvc/llvm-project?rev=292744&view=rev
Log:
[libFuzzer] Fix OutOfMemory tests to work on 32 bits.

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

Modified:
    llvm/trunk/lib/Fuzzer/test/OutOfMemorySingleLargeMallocTest.cpp
    llvm/trunk/lib/Fuzzer/test/fuzzer-oom.test

Modified: llvm/trunk/lib/Fuzzer/test/OutOfMemorySingleLargeMallocTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/OutOfMemorySingleLargeMallocTest.cpp?rev=292744&r1=292743&r2=292744&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/OutOfMemorySingleLargeMallocTest.cpp (original)
+++ llvm/trunk/lib/Fuzzer/test/OutOfMemorySingleLargeMallocTest.cpp Sat Jan 21 19:58:50 2017
@@ -15,7 +15,7 @@ extern "C" int LLVMFuzzerTestOneInput(co
   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;

Modified: llvm/trunk/lib/Fuzzer/test/fuzzer-oom.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/fuzzer-oom.test?rev=292744&r1=292743&r2=292744&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/fuzzer-oom.test (original)
+++ llvm/trunk/lib/Fuzzer/test/fuzzer-oom.test Sat Jan 21 19:58:50 2017
@@ -3,8 +3,8 @@ CHECK: ERROR: libFuzzer: out-of-memory (
 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.




More information about the llvm-commits mailing list