-
Notifications
You must be signed in to change notification settings - Fork 784
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Buffer parser fuzzing * add clang-6 with libfuzzer base Dockerfile Co-authored-by: Russel Waters <vaelstrom@gmail.com>
- Loading branch information
1 parent
a752deb
commit d41d4c5
Showing
6 changed files
with
132 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
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,22 @@ | ||
FROM nanocurrency/nano-env:base | ||
|
||
RUN apt-get update && apt-get install -yqq software-properties-common && \ | ||
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \ | ||
apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-6.0 main" && \ | ||
apt-get update -qq && apt-get install -yqq \ | ||
clang-6.0 lldb-6.0 libfuzzer-6.0-dev git | ||
|
||
ADD util/build_prep/fetch_rocksdb.sh fetch_rocksdb.sh | ||
RUN ./fetch_rocksdb.sh | ||
|
||
ENV CXX=/usr/bin/clang++ | ||
ENV CC=/usr/bin/clang | ||
RUN ln -s /usr/bin/clang-6.0 /usr/bin/clang | ||
RUN ln -s /usr/bin/clang++-6.0 /usr/bin/clang++ | ||
RUN update-alternatives --install /usr/bin/cc cc /usr/bin/clang 100 | ||
RUN update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 100 | ||
ENV BOOST_ROOT=/tmp/boost | ||
|
||
ADD util/build_prep/bootstrap_boost.sh bootstrap_boost.sh | ||
|
||
RUN ./bootstrap_boost.sh -m -c -B 1.70 |
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,3 @@ | ||
add_executable(fuzz_buffer fuzz_buffer.cpp) | ||
target_compile_options(fuzz_buffer PUBLIC -fsanitize=fuzzer) | ||
target_link_libraries(fuzz_buffer 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,75 @@ | ||
#include <nano/core_test/testutil.hpp> | ||
#include <nano/node/common.hpp> | ||
#include <nano/node/testing.hpp> | ||
|
||
#include <cstddef> | ||
#include <cstdint> | ||
#include <cstdio> | ||
#include <cstdlib> | ||
#include <iostream> | ||
|
||
namespace nano | ||
{ | ||
void force_nano_test_network (); | ||
} | ||
namespace | ||
{ | ||
std::shared_ptr<nano::system> system0; | ||
std::shared_ptr<nano::node> node0; | ||
|
||
class fuzz_visitor : public nano::message_visitor | ||
{ | ||
public: | ||
virtual void keepalive (nano::keepalive const &) override | ||
{ | ||
} | ||
virtual void publish (nano::publish const &) override | ||
{ | ||
} | ||
virtual void confirm_req (nano::confirm_req const &) override | ||
{ | ||
} | ||
virtual void confirm_ack (nano::confirm_ack const &) override | ||
{ | ||
} | ||
virtual void bulk_pull (nano::bulk_pull const &) override | ||
{ | ||
} | ||
virtual void bulk_pull_account (nano::bulk_pull_account const &) override | ||
{ | ||
} | ||
virtual void bulk_push (nano::bulk_push const &) override | ||
{ | ||
} | ||
virtual void frontier_req (nano::frontier_req const &) override | ||
{ | ||
} | ||
virtual void node_id_handshake (nano::node_id_handshake const &) override | ||
{ | ||
} | ||
}; | ||
} | ||
|
||
/** Fuzz live message parsing. This covers parsing and block/vote uniquing. */ | ||
void fuzz_message_parser (const uint8_t * Data, size_t Size) | ||
{ | ||
static bool initialized = false; | ||
if (!initialized) | ||
{ | ||
nano::force_nano_test_network (); | ||
initialized = true; | ||
system0 = std::make_shared<nano::system> (1); | ||
node0 = system0->nodes[0]; | ||
} | ||
|
||
fuzz_visitor visitor; | ||
nano::message_parser parser (node0->block_uniquer, node0->vote_uniquer, visitor, node0->work); | ||
parser.deserialize_buffer (Data, Size); | ||
} | ||
|
||
/** Fuzzer entry point */ | ||
extern "C" int LLVMFuzzerTestOneInput (const uint8_t * Data, size_t Size) | ||
{ | ||
fuzz_message_parser (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
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