This repository has been archived by the owner on Apr 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add OS fuzzing for SendBatches endpoint * Add fuzzing for request proposal endpoint Signed-off-by: luckychess <[email protected]> Signed-off-by: Konstantin Munichev <[email protected]>
- Loading branch information
1 parent
0a38453
commit f23dcea
Showing
5 changed files
with
182 additions
and
29 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
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,63 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef IROHA_ORDERING_SERVICE_FIXTURE_HPP | ||
#define IROHA_ORDERING_SERVICE_FIXTURE_HPP | ||
|
||
#include <memory> | ||
|
||
#include <gtest/gtest.h> | ||
#include <libfuzzer/libfuzzer_macro.h> | ||
|
||
#include "backend/protobuf/proto_transport_factory.hpp" | ||
#include "backend/protobuf/transaction.hpp" | ||
#include "interfaces/iroha_internal/transaction_batch_factory_impl.hpp" | ||
#include "interfaces/iroha_internal/transaction_batch_impl.hpp" | ||
#include "interfaces/iroha_internal/transaction_batch_parser_impl.hpp" | ||
#include "module/shared_model/interface/mock_transaction_batch_factory.hpp" | ||
#include "module/shared_model/interface_mocks.hpp" | ||
#include "module/shared_model/validators/validators.hpp" | ||
#include "ordering/impl/on_demand_ordering_service_impl.hpp" | ||
#include "ordering/impl/on_demand_os_server_grpc.hpp" | ||
|
||
using namespace testing; | ||
using namespace iroha::ordering; | ||
using namespace iroha::ordering::transport; | ||
|
||
namespace fuzzing { | ||
struct OrderingServiceFixture { | ||
std::shared_ptr<OnDemandOsServerGrpc::TransportFactoryType> | ||
transaction_factory_; | ||
std::shared_ptr<shared_model::interface::TransactionBatchParser> | ||
batch_parser_; | ||
std::shared_ptr<NiceMock<MockTransactionBatchFactory>> | ||
transaction_batch_factory_; | ||
NiceMock<shared_model::validation::MockValidator< | ||
shared_model::interface::Transaction>> *transaction_validator_; | ||
|
||
OrderingServiceFixture() { | ||
// fuzzing target is intended to run many times (~millions) so any | ||
// additional output slows it down significantly | ||
spdlog::set_level(spdlog::level::err); | ||
|
||
auto transaction_validator = | ||
std::make_unique<NiceMock<shared_model::validation::MockValidator< | ||
shared_model::interface::Transaction>>>(); | ||
transaction_validator_ = transaction_validator.get(); | ||
transaction_factory_ = | ||
std::make_shared<shared_model::proto::ProtoTransportFactory< | ||
shared_model::interface::Transaction, | ||
shared_model::proto::Transaction>>( | ||
std::move(transaction_validator)); | ||
|
||
batch_parser_ = std::make_shared< | ||
shared_model::interface::TransactionBatchParserImpl>(); | ||
transaction_batch_factory_ = | ||
std::make_shared<NiceMock<MockTransactionBatchFactory>>(); | ||
} | ||
}; | ||
} // namespace fuzzing | ||
|
||
#endif // IROHA_ORDERING_SERVICE_FIXTURE_HPP |
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 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "ordering_service_fixture.hpp" | ||
|
||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, std::size_t size) { | ||
static fuzzing::OrderingServiceFixture fixture; | ||
|
||
if (size < 1) { | ||
return 0; | ||
} | ||
|
||
std::shared_ptr<OnDemandOrderingServiceImpl> ordering_service_; | ||
std::shared_ptr<OnDemandOsServerGrpc> server_; | ||
|
||
auto proposal_factory = std::make_unique<MockUnsafeProposalFactory>(); | ||
ordering_service_ = std::make_shared<OnDemandOrderingServiceImpl>( | ||
data[0], std::move(proposal_factory)); | ||
server_ = std::make_shared<OnDemandOsServerGrpc>( | ||
ordering_service_, | ||
fixture.transaction_factory_, | ||
fixture.batch_parser_, | ||
fixture.transaction_batch_factory_); | ||
|
||
proto::ProposalRequest request; | ||
if (protobuf_mutator::libfuzzer::LoadProtoInput( | ||
true, data + 1, size - 1, &request)) { | ||
grpc::ServerContext context; | ||
proto::ProposalResponse response; | ||
server_->RequestProposal(&context, &request, &response); | ||
} | ||
|
||
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,36 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "ordering_service_fixture.hpp" | ||
|
||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, std::size_t size) { | ||
static fuzzing::OrderingServiceFixture fixture; | ||
|
||
if (size < 1) { | ||
return 0; | ||
} | ||
|
||
std::shared_ptr<OnDemandOrderingServiceImpl> ordering_service_; | ||
std::shared_ptr<OnDemandOsServerGrpc> server_; | ||
|
||
auto proposal_factory = std::make_unique<MockUnsafeProposalFactory>(); | ||
ordering_service_ = std::make_shared<OnDemandOrderingServiceImpl>( | ||
data[0], std::move(proposal_factory)); | ||
server_ = std::make_shared<OnDemandOsServerGrpc>( | ||
ordering_service_, | ||
fixture.transaction_factory_, | ||
fixture.batch_parser_, | ||
fixture.transaction_batch_factory_); | ||
|
||
proto::BatchesRequest request; | ||
if (protobuf_mutator::libfuzzer::LoadProtoInput( | ||
true, data + 1, size - 1, &request)) { | ||
grpc::ServerContext context; | ||
google::protobuf::Empty response; | ||
server_->SendBatches(&context, &request, &response); | ||
} | ||
|
||
return 0; | ||
} |