mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
merge bitcoin#17291: Add fuzzing harness for ISO-8601 related functions
This commit is contained in:
parent
fd4c6f8239
commit
166232b6f3
@ -102,7 +102,7 @@ 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
|
||||
```
|
||||
|
||||
|
@ -35,6 +35,7 @@ FUZZ_TARGETS = \
|
||||
test/fuzz/messageheader_deserialize \
|
||||
test/fuzz/netaddr_deserialize \
|
||||
test/fuzz/out_point_deserialize \
|
||||
test/fuzz/parse_iso8601 \
|
||||
test/fuzz/partial_merkle_tree_deserialize \
|
||||
test/fuzz/partially_signed_transaction_deserialize \
|
||||
test/fuzz/prefilled_transaction_deserialize \
|
||||
@ -321,6 +322,12 @@ test_fuzz_netaddr_deserialize_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
test_fuzz_netaddr_deserialize_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(LDFLAGS_WRAP_EXCEPTIONS)
|
||||
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) $(LDFLAGS_WRAP_EXCEPTIONS)
|
||||
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)
|
||||
|
32
src/test/fuzz/parse_iso8601.cpp
Normal file
32
src/test/fuzz/parse_iso8601.cpp
Normal 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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user