🐛 fixed AFL driver to also read binary data

This commit is contained in:
Niels Lohmann 2016-12-25 16:06:56 +01:00
parent dbdcb3fec8
commit 6de9d4035a

View file

@ -11,9 +11,9 @@ passed byte array.
Licensed under the MIT License <http://opensource.org/licenses/MIT>. Licensed under the MIT License <http://opensource.org/licenses/MIT>.
*/ */
#include <sstream> #include <vector> // for vector
#include <cstdint> #include <cstdint> // for uint8_t
#include <iostream> #include <iostream> // for cin
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size); extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
@ -23,10 +23,15 @@ int main()
while (__AFL_LOOP(1000)) while (__AFL_LOOP(1000))
{ {
#endif #endif
// copy stdin to stringstream to pass it to fuzzer as byte array // copy stdin to byte vector
std::stringstream ss; std::vector<uint8_t> vec;
ss << std::cin.rdbuf(); char c;
LLVMFuzzerTestOneInput(reinterpret_cast<const uint8_t*>(ss.str().c_str()), ss.str().size()); while (std::cin.get(c))
{
vec.push_back(static_cast<uint8_t>(c));
}
LLVMFuzzerTestOneInput(vec.data(), vec.size());
#ifdef __AFL_HAVE_MANUAL_CONTROL #ifdef __AFL_HAVE_MANUAL_CONTROL
} }
#endif #endif