aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Fuzzer/test/OutOfMemorySingleLargeMallocTest.cpp
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2016-11-30 22:39:35 +0000
committerKostya Serebryany <kcc@google.com>2016-11-30 22:39:35 +0000
commit05f7791fbf59e5a19ff79ed1175e7042100da8e8 (patch)
treeeab47f91a9cf15f815cb14924d9c0c5c32dd324a /llvm/lib/Fuzzer/test/OutOfMemorySingleLargeMallocTest.cpp
parent5cb34077e879c03d460dedad7aaa421bd2bd08a3 (diff)
downloadllvm-05f7791fbf59e5a19ff79ed1175e7042100da8e8.zip
llvm-05f7791fbf59e5a19ff79ed1175e7042100da8e8.tar.gz
llvm-05f7791fbf59e5a19ff79ed1175e7042100da8e8.tar.bz2
[libFuzzer] extend -rss_limit_mb to crash instantly on a single malloc that exceeds the limit
llvm-svn: 288281
Diffstat (limited to 'llvm/lib/Fuzzer/test/OutOfMemorySingleLargeMallocTest.cpp')
-rw-r--r--llvm/lib/Fuzzer/test/OutOfMemorySingleLargeMallocTest.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/llvm/lib/Fuzzer/test/OutOfMemorySingleLargeMallocTest.cpp b/llvm/lib/Fuzzer/test/OutOfMemorySingleLargeMallocTest.cpp
new file mode 100644
index 0000000..5d95c42
--- /dev/null
+++ b/llvm/lib/Fuzzer/test/OutOfMemorySingleLargeMallocTest.cpp
@@ -0,0 +1,28 @@
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+
+// Tests OOM handling.
+#include <assert.h>
+#include <cstdint>
+#include <cstdlib>
+#include <cstddef>
+#include <cstring>
+#include <iostream>
+#include <unistd.h>
+
+static volatile char *SinkPtr;
+
+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;
+ char *p = new char[kSize];
+ SinkPtr = p;
+ delete [] p;
+ }
+ }
+ }
+ return 0;
+}
+