Merge #17291: tests: Add fuzzing harness for ISO-8601 related functions

595cc9bcaf docs: Add undefined to --with-sanitizers=fuzzer,address (practicalswift)
d5dbb4898c tests: Add fuzzing harness for ISO-8601 related functions (practicalswift)

Pull request description:

  Add fuzzing harness for ISO-8601 related functions.

  **Testing this PR**

  Run:

  ```
  $ CC=clang CXX=clang++ ./configure --enable-fuzz \
        --with-sanitizers=address,fuzzer,undefined
  $ make
  $ src/test/fuzz/parse_iso8601
  …
  ```

Top commit has no ACKs.

Tree-SHA512: 8d4ad9e4eef546e97ea330cf518fdd7241c6f016d6c45c011369d5cdd832bbbc3564d1a990c953ffb33b0c05e58f5533e7b6fd77062f8484df36da1513567915
This commit is contained in:
MarcoFalke 2019-10-30 10:16:55 -04:00
commit 341e8d355d
No known key found for this signature in database
GPG key ID: D2EA4850E7528B25
3 changed files with 41 additions and 2 deletions

View file

@ -77,13 +77,13 @@ will print an error and suggestion if so.
## libFuzzer
A recent version of `clang`, the address sanitizer and libFuzzer is needed (all
A recent version of `clang`, the address/undefined sanitizers (ASan/UBSan) and libFuzzer is needed (all
found in the `compiler-rt` runtime libraries package).
To build all fuzz targets with libFuzzer, run
```
./configure --disable-ccache --enable-fuzz --with-sanitizers=fuzzer,address CC=clang CXX=clang++
./configure --disable-ccache --enable-fuzz --with-sanitizers=fuzzer,address,undefined CC=clang CXX=clang++
make
```

View file

@ -22,6 +22,7 @@ FUZZ_TARGETS = \
test/fuzz/inv_deserialize \
test/fuzz/messageheader_deserialize \
test/fuzz/netaddr_deserialize \
test/fuzz/parse_iso8601 \
test/fuzz/script \
test/fuzz/script_flags \
test/fuzz/service_deserialize \
@ -269,6 +270,12 @@ test_fuzz_netaddr_deserialize_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
test_fuzz_netaddr_deserialize_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
test_fuzz_netaddr_deserialize_LDADD = $(FUZZ_SUITE_LD_COMMON)
test_fuzz_parse_iso8601_SOURCES = $(FUZZ_SUITE) test/fuzz/parse_iso8601.cpp
test_fuzz_parse_iso8601_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
test_fuzz_parse_iso8601_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
test_fuzz_parse_iso8601_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
test_fuzz_parse_iso8601_LDADD = $(FUZZ_SUITE_LD_COMMON)
test_fuzz_script_SOURCES = $(FUZZ_SUITE) test/fuzz/script.cpp
test_fuzz_script_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
test_fuzz_script_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)

View file

@ -0,0 +1,32 @@
// Copyright (c) 2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <util/time.h>
#include <cassert>
#include <cstdint>
#include <string>
#include <vector>
void test_one_input(const std::vector<uint8_t>& buffer)
{
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
const int64_t random_time = fuzzed_data_provider.ConsumeIntegral<int64_t>();
const std::string random_string = fuzzed_data_provider.ConsumeRemainingBytesAsString();
const std::string iso8601_datetime = FormatISO8601DateTime(random_time);
const int64_t parsed_time_1 = ParseISO8601DateTime(iso8601_datetime);
if (random_time >= 0) {
assert(parsed_time_1 >= 0);
if (iso8601_datetime.length() == 20) {
assert(parsed_time_1 == random_time);
}
}
const int64_t parsed_time_2 = ParseISO8601DateTime(random_string);
assert(parsed_time_2 >= 0);
}