Avoid accumulating allocated memory in a global state if LogPrintf is called when fuzzing.
The accumulation takes place via the m_msgs_before_open buffering.
Resolved by enabling logging and writing log messages to standard output.
This has the added benefit of making the fuzzing operator aware of any log printing caused by fuzzing which is likely to be an anomaly in itself (in the general case).
The only fuzzing harness in master that I've seen calling LogPrintf is messageheader_deserialize via the call to CMessageHeader::IsValid() which somewhat surprisingly does a LogPrintf in the case of nMessageSize > MAX_SIZE :)
Before:
$ src/test/fuzz/messageheader_deserialize corpus/
…
INFO: libFuzzer disabled leak detection after every mutation.
Most likely the target function accumulates allocated
memory in a global state w/o actually leaking it.
You may try running this binary with -trace_malloc=[12]
to get a trace of mallocs and frees.
If LeakSanitizer is enabled in this process it will still
run on the process shutdown.
…
After:
$ src/test/fuzz/messageheader_deserialize corpus/
…
2020-01-07T23:20:34Z CMessageHeader::IsValid(): (@, 4278190080 bytes) nMessageSize > MAX_SIZE
…
How to test this PR
$ make distclean
$ ./autogen.sh
$ CC=clang CXX=clang++ ./configure --enable-fuzz \
--with-sanitizers=address,fuzzer,undefined
$ make
$ src/test/fuzz/messageheader_deserialize
…