aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvan Hauser <vh@thc.org>2021-10-03 17:25:11 +0200
committerGitHub <noreply@github.com>2021-10-03 17:25:11 +0200
commit8bde2bb13e4656c32e5d061bcd42a87b7c8b7bfa (patch)
treeb1fdf044e785abade0dfbb59577277cc4c959154
parent5df7b12b757884c17168a4aece1e57b13d0b7f3f (diff)
parent716d2029c0c2557486488ce6bb7910df9ce4ffcb (diff)
downloadafl++-8bde2bb13e4656c32e5d061bcd42a87b7c8b7bfa.tar.gz
Merge pull request #1097 from devnexen/llvm_lto_inst_dict
LLVM LTO plugin using smart pointer for __afl_internal_directory vari…
-rw-r--r--instrumentation/afl-llvm-lto-instrumentation.so.cc17
1 files changed, 6 insertions, 11 deletions
diff --git a/instrumentation/afl-llvm-lto-instrumentation.so.cc b/instrumentation/afl-llvm-lto-instrumentation.so.cc
index e300044c..4a5738de 100644
--- a/instrumentation/afl-llvm-lto-instrumentation.so.cc
+++ b/instrumentation/afl-llvm-lto-instrumentation.so.cc
@@ -28,6 +28,7 @@
#include <sys/time.h>
#include <list>
+#include <memory>
#include <string>
#include <fstream>
#include <set>
@@ -1015,13 +1016,7 @@ bool AFLLTOPass::runOnModule(Module &M) {
if (count) {
- if ((ptr = (char *)malloc(memlen + count)) == NULL) {
-
- fprintf(stderr, "Error: malloc for %zu bytes failed!\n",
- memlen + count);
- exit(-1);
-
- }
+ auto ptrhld = std::unique_ptr<char []>(new char[memlen + count]);
count = 0;
@@ -1030,8 +1025,8 @@ bool AFLLTOPass::runOnModule(Module &M) {
if (offset + token.length() < 0xfffff0 && count < MAX_AUTO_EXTRAS) {
- ptr[offset++] = (uint8_t)token.length();
- memcpy(ptr + offset, token.c_str(), token.length());
+ ptrhld.get()[offset++] = (uint8_t)token.length();
+ memcpy(ptrhld.get() + offset, token.c_str(), token.length());
offset += token.length();
count++;
@@ -1051,10 +1046,10 @@ bool AFLLTOPass::runOnModule(Module &M) {
GlobalVariable *AFLInternalDictionary = new GlobalVariable(
M, ArrayTy, true, GlobalValue::ExternalLinkage,
ConstantDataArray::get(C,
- *(new ArrayRef<char>((char *)ptr, offset))),
+ *(new ArrayRef<char>(ptrhld.get(), offset))),
"__afl_internal_dictionary");
AFLInternalDictionary->setInitializer(ConstantDataArray::get(
- C, *(new ArrayRef<char>((char *)ptr, offset))));
+ C, *(new ArrayRef<char>(ptrhld.get(), offset))));
AFLInternalDictionary->setConstant(true);
GlobalVariable *AFLDictionary = new GlobalVariable(