-
Notifications
You must be signed in to change notification settings - Fork 786
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fuzz account, hex, dec and endpoint parsing (#2523)
- Loading branch information
1 parent
dc8b7ad
commit 17b9e8f
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
add_executable(fuzz_buffer fuzz_buffer.cpp) | ||
target_compile_options(fuzz_buffer PUBLIC -fsanitize=fuzzer) | ||
target_link_libraries(fuzz_buffer PRIVATE -fsanitize=fuzzer node) | ||
|
||
add_executable(fuzz_bignum fuzz_bignum.cpp) | ||
target_compile_options(fuzz_bignum PUBLIC -fsanitize=fuzzer) | ||
target_link_libraries(fuzz_bignum PRIVATE -fsanitize=fuzzer node) | ||
|
||
add_executable(fuzz_endpoint_parsing fuzz_endpoint_parsing.cpp) | ||
target_compile_options(fuzz_endpoint_parsing PUBLIC -fsanitize=fuzzer) | ||
target_link_libraries(fuzz_endpoint_parsing PRIVATE -fsanitize=fuzzer node) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <nano/node/common.hpp> | ||
|
||
/** Fuzz decimal, hex and account parsing */ | ||
void fuzz_bignum_parsers (const uint8_t * Data, size_t Size) | ||
{ | ||
try | ||
{ | ||
auto data (std::string (reinterpret_cast<char *> (const_cast<uint8_t *> (Data)), Size)); | ||
nano::uint128_union u128; | ||
u128.decode_dec (data); | ||
u128.decode_hex (data); | ||
|
||
nano::uint256_union u256; | ||
u256.decode_dec (data); | ||
u256.decode_hex (data); | ||
|
||
nano::uint512_union u512; | ||
u512.decode_hex (data); | ||
|
||
nano::public_key pkey; | ||
pkey.decode_account (data); | ||
|
||
uint64_t out; | ||
nano::from_string_hex (data, out); | ||
} | ||
catch (std::out_of_range const &) | ||
{ | ||
} | ||
} | ||
|
||
/** Fuzzer entry point */ | ||
extern "C" int LLVMFuzzerTestOneInput (const uint8_t * Data, size_t Size) | ||
{ | ||
fuzz_bignum_parsers (Data, Size); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <nano/node/common.hpp> | ||
|
||
/** Fuzz endpoint parsing */ | ||
void fuzz_endpoint_parsing (const uint8_t * Data, size_t Size) | ||
{ | ||
auto data (std::string (reinterpret_cast<char *> (const_cast<uint8_t *> (Data)), Size)); | ||
nano::endpoint endpoint; | ||
nano::parse_endpoint (data, endpoint); | ||
nano::tcp_endpoint tcp_endpoint; | ||
nano::parse_tcp_endpoint (data, tcp_endpoint); | ||
} | ||
|
||
/** Fuzzer entry point */ | ||
extern "C" int LLVMFuzzerTestOneInput (const uint8_t * Data, size_t Size) | ||
{ | ||
fuzz_endpoint_parsing (Data, Size); | ||
return 0; | ||
} |