[PATCH] D28706: [libFuzzer] Fix Out of Memory tests to work on 32 bits.

Marcos Pividori via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 13 15:04:03 PST 2017


mpividori created this revision.
mpividori added reviewers: kcc, zturner.
mpividori added a subscriber: llvm-commits.
mpividori set the repository for this revision to rL LLVM.

Hi,
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`.


Repository:
  rL LLVM

https://reviews.llvm.org/D28706

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


Index: lib/Fuzzer/test/fuzzer-oom.test
===================================================================
--- lib/Fuzzer/test/fuzzer-oom.test
+++ lib/Fuzzer/test/fuzzer-oom.test
@@ -3,8 +3,8 @@
 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.
Index: lib/Fuzzer/test/OutOfMemorySingleLargeMallocTest.cpp
===================================================================
--- lib/Fuzzer/test/OutOfMemorySingleLargeMallocTest.cpp
+++ lib/Fuzzer/test/OutOfMemorySingleLargeMallocTest.cpp
@@ -15,7 +15,7 @@
   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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28706.84392.patch
Type: text/x-patch
Size: 1273 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170113/c5c7821e/attachment.bin>


More information about the llvm-commits mailing list