Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Commit

Permalink
Add fuzzing target for consensus
Browse files Browse the repository at this point in the history
Signed-off-by: Konstantin Munichev <toobwn@gmail.com>
  • Loading branch information
luckychess committed Nov 8, 2018
1 parent 1b1966b commit c6eaa2d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/fuzzing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,11 @@ target_link_libraries(request_proposal_fuzz
on_demand_ordering_service_transport_grpc
protobuf-mutator
)

add_executable(consensus_fuzz consensus_fuzz.cpp)
target_link_libraries(consensus_fuzz
gtest::gtest
gmock::gmock
yac_transport
protobuf-mutator
)
54 changes: 54 additions & 0 deletions test/fuzzing/consensus_fuzz.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

#include <memory>

#include <gtest/gtest.h>
#include <libfuzzer/libfuzzer_macro.h>

#include "consensus/yac/transport/impl/network_impl.hpp"
#include "module/irohad/consensus/yac/yac_mocks.hpp"

using namespace testing;

namespace fuzzing {
struct ConsensusFixture {
std::shared_ptr<
NiceMock<iroha::consensus::yac::MockYacNetworkNotifications>>
notifications_;
std::shared_ptr<iroha::network::AsyncGrpcClient<google::protobuf::Empty>>
async_call_;
std::shared_ptr<iroha::consensus::yac::NetworkImpl> network_;

ConsensusFixture() {
spdlog::set_level(spdlog::level::critical);

notifications_ = std::make_shared<
NiceMock<iroha::consensus::yac::MockYacNetworkNotifications>>();
async_call_ = std::make_shared<
iroha::network::AsyncGrpcClient<google::protobuf::Empty>>();
network_ =
std::make_shared<iroha::consensus::yac::NetworkImpl>(async_call_);
network_->subscribe(notifications_);
}
};
} // namespace fuzzing

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, std::size_t size) {
static fuzzing::ConsensusFixture fixture;

if (size < 1) {
return 0;
}

iroha::consensus::yac::proto::State request;
if (protobuf_mutator::libfuzzer::LoadProtoInput(true, data, size, &request)) {
grpc::ServerContext context;
google::protobuf::Empty response;
fixture.network_->SendState(&context, &request, &response);
}

return 0;
}

0 comments on commit c6eaa2d

Please sign in to comment.