Hi Konstantin,
thank you for your reply.
> Also, not sure what do you mean by "the "data" array generated by the fuzzer".
Here I meant the uint8_t * data array passed to the fuzz target.
But I think I should elaborate more on what I am trying.
In the code below, I consider inserting two calls to printf: the
first one is
printf("%f %f\n", x, y);
and prints the input parameters to my function at each iteration,
while the second one is inside the if block. I compare two builds
obtained enabling and commenting out the second call to printf.
The code is compiled with
clang -Wall --pedantic -g -ggdb -O1 -fsanitize=fuzzer,address,signed-integer-overflow test_with_printf.cpp -o test_with_printf
with
$ clang --version
Target: x86_64-unknown-linux-gnu
Thread model: posix
I now run both executables with
The first printf prints different numbers depending whether the second
call to printf is commented out or not. More precisely, the output is
the same for the first 337 iterations and starts to differ from
iteration 338.
The results are reproducible: multiple runs of the same code version
give identical results.
The preamble written by the fuzzer is also different in the two cases:
1) for the case with commented out printf call:
INFO: Running with entropic power schedule (0xFF, 100).
INFO: Loaded 1 modules (19 inline 8-bit counters): 19 [0x789040, 0x789053),
INFO: Loaded 1 PC tables (19 PCs): 19 [0x562720,0x562850),
INFO: -max_len is not provided; libFuzzer will not generate inputs larger than 4096 bytes
INFO: A corpus is not provided, starting from an empty corpus
#2 INITED cov: 8 ft: 8 corp: 1/1b exec/s: 0 rss: 30Mb
#5 NEW cov: 8 ft: 10 corp: 2/3b lim: 4 exec/s: 0 rss: 30Mb L: 2/2 MS: 3 CrossOver-ChangeBit-CrossOver-
#9 NEW cov: 8 ft: 12 corp: 3/6b lim: 4 exec/s: 0 rss: 30Mb L: 3/3 MS: 4 ShuffleBytes-ChangeBinInt-ChangeBit-InsertByte-
#13 NEW cov: 9 ft: 14 corp: 4/10b lim: 4 exec/s: 0 rss: 30Mb L: 4/4 MS: 4 InsertByte-ChangeBit-ChangeBit-CrossOver-
2) for the case with enabled printf call
INFO: Running with entropic power schedule (0xFF, 100).
INFO: Loaded 1 modules (20 inline 8-bit counters): 20 [0x789080, 0x789094),
INFO: Loaded 1 PC tables (20 PCs): 20 [0x5627a0,0x5628e0),
INFO: -max_len is not provided; libFuzzer will not generate inputs larger than 4096 bytes
INFO: A corpus is not provided, starting from an empty corpus
#2 INITED cov: 7 ft: 7 corp: 1/1b exec/s: 0 rss: 29Mb
#5 NEW cov: 7 ft: 9 corp: 2/3b lim: 4 exec/s: 0 rss: 30Mb L: 2/2 MS: 3 CrossOver-ChangeBit-CrossOver-
#9 NEW cov: 7 ft: 11 corp: 3/6b lim: 4 exec/s: 0 rss: 30Mb L: 3/3 MS: 4 ShuffleBytes-ChangeBinInt-ChangeBit-InsertByte-
#13 NEW cov: 9 ft: 14 corp: 4/10b lim: 4 exec/s: 0 rss: 30Mb L: 4/4 MS: 4 InsertByte-ChangeBit-ChangeBit-CrossOver-
Here is the code:
#include <fenv.h>
#include <stdio.h>
#include <fuzzer/FuzzedDataProvider.h>
float f( float const x, float const y )
{
float z = 0.0f;
printf("%f %f\n", x, y);
if( ( 322.56f < x ) && ( x < 322.57f ) )
{
// printf("Inside the if block\n");
z -= x;
}
return z;
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t * const data, size_t const size)
{
FuzzedDataProvider provider(data, size);
auto x = provider.ConsumeFloatingPointInRange<float>(0.0f,1000.0f);
auto y = provider.ConsumeFloatingPoint<float>();
f( x, y );
return 0;
}
extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
{
feenableexcept( FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW );
return 0;
}