From 6de9d4035a3becaa7d92812ca3ededfaf9a0cb29 Mon Sep 17 00:00:00 2001 From: Niels Lohmann <niels.lohmann@gmail.com> Date: Sun, 25 Dec 2016 16:06:56 +0100 Subject: [PATCH] :bug: fixed AFL driver to also read binary data --- test/src/fuzzer-driver_afl.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/test/src/fuzzer-driver_afl.cpp b/test/src/fuzzer-driver_afl.cpp index e386033a..eddeae41 100644 --- a/test/src/fuzzer-driver_afl.cpp +++ b/test/src/fuzzer-driver_afl.cpp @@ -11,9 +11,9 @@ passed byte array. Licensed under the MIT License <http://opensource.org/licenses/MIT>. */ -#include <sstream> -#include <cstdint> -#include <iostream> +#include <vector> // for vector +#include <cstdint> // for uint8_t +#include <iostream> // for cin extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size); @@ -23,10 +23,15 @@ int main() while (__AFL_LOOP(1000)) { #endif - // copy stdin to stringstream to pass it to fuzzer as byte array - std::stringstream ss; - ss << std::cin.rdbuf(); - LLVMFuzzerTestOneInput(reinterpret_cast<const uint8_t*>(ss.str().c_str()), ss.str().size()); + // copy stdin to byte vector + std::vector<uint8_t> vec; + char c; + while (std::cin.get(c)) + { + vec.push_back(static_cast<uint8_t>(c)); + } + + LLVMFuzzerTestOneInput(vec.data(), vec.size()); #ifdef __AFL_HAVE_MANUAL_CONTROL } #endif