Skip to content

Commit 341e8d3

Browse files
author
MarcoFalke
committed
Merge #17291: tests: Add fuzzing harness for ISO-8601 related functions
595cc9b docs: Add undefined to --with-sanitizers=fuzzer,address (practicalswift) d5dbb48 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
2 parents edd9d07 + 595cc9b commit 341e8d3

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

doc/fuzzing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ will print an error and suggestion if so.
7777

7878
## libFuzzer
7979

80-
A recent version of `clang`, the address sanitizer and libFuzzer is needed (all
80+
A recent version of `clang`, the address/undefined sanitizers (ASan/UBSan) and libFuzzer is needed (all
8181
found in the `compiler-rt` runtime libraries package).
8282

8383
To build all fuzz targets with libFuzzer, run
8484

8585
```
86-
./configure --disable-ccache --enable-fuzz --with-sanitizers=fuzzer,address CC=clang CXX=clang++
86+
./configure --disable-ccache --enable-fuzz --with-sanitizers=fuzzer,address,undefined CC=clang CXX=clang++
8787
make
8888
```
8989

src/Makefile.test.include

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ FUZZ_TARGETS = \
2222
test/fuzz/inv_deserialize \
2323
test/fuzz/messageheader_deserialize \
2424
test/fuzz/netaddr_deserialize \
25+
test/fuzz/parse_iso8601 \
2526
test/fuzz/script \
2627
test/fuzz/script_flags \
2728
test/fuzz/service_deserialize \
@@ -269,6 +270,12 @@ test_fuzz_netaddr_deserialize_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
269270
test_fuzz_netaddr_deserialize_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
270271
test_fuzz_netaddr_deserialize_LDADD = $(FUZZ_SUITE_LD_COMMON)
271272

273+
test_fuzz_parse_iso8601_SOURCES = $(FUZZ_SUITE) test/fuzz/parse_iso8601.cpp
274+
test_fuzz_parse_iso8601_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
275+
test_fuzz_parse_iso8601_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
276+
test_fuzz_parse_iso8601_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
277+
test_fuzz_parse_iso8601_LDADD = $(FUZZ_SUITE_LD_COMMON)
278+
272279
test_fuzz_script_SOURCES = $(FUZZ_SUITE) test/fuzz/script.cpp
273280
test_fuzz_script_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
274281
test_fuzz_script_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)

src/test/fuzz/parse_iso8601.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) 2019 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include <test/fuzz/FuzzedDataProvider.h>
6+
#include <test/fuzz/fuzz.h>
7+
#include <util/time.h>
8+
9+
#include <cassert>
10+
#include <cstdint>
11+
#include <string>
12+
#include <vector>
13+
14+
void test_one_input(const std::vector<uint8_t>& buffer)
15+
{
16+
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
17+
18+
const int64_t random_time = fuzzed_data_provider.ConsumeIntegral<int64_t>();
19+
const std::string random_string = fuzzed_data_provider.ConsumeRemainingBytesAsString();
20+
21+
const std::string iso8601_datetime = FormatISO8601DateTime(random_time);
22+
const int64_t parsed_time_1 = ParseISO8601DateTime(iso8601_datetime);
23+
if (random_time >= 0) {
24+
assert(parsed_time_1 >= 0);
25+
if (iso8601_datetime.length() == 20) {
26+
assert(parsed_time_1 == random_time);
27+
}
28+
}
29+
30+
const int64_t parsed_time_2 = ParseISO8601DateTime(random_string);
31+
assert(parsed_time_2 >= 0);
32+
}

0 commit comments

Comments
 (0)