Skip to content

Commit

Permalink
Listener Fuzzer: avoid dangling reference to dtor unique_ptr (#23537)
Browse files Browse the repository at this point in the history
Let fuzzer own filter to avoid dangling reference if listener filter
chain doesn't get created in connect.

Signed-off-by: Kevin Baichoo <[email protected]>
  • Loading branch information
KBaichoo authored Oct 21, 2022
1 parent 9dcd806 commit 2f6f60d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ ListenerFilterWithDataFuzzer::ListenerFilterWithDataFuzzer()
conn_->addConnectionCallbacks(connection_callbacks_);
}

void ListenerFilterWithDataFuzzer::connect(Network::ListenerFilterPtr filter) {
void ListenerFilterWithDataFuzzer::connect() {
EXPECT_CALL(factory_, createListenerFilterChain(_))
.WillOnce(Invoke([&](Network::ListenerFilterManager& filter_manager) -> bool {
filter_manager.addAcceptFilter(nullptr, std::move(filter));
.WillOnce(Invoke([this](Network::ListenerFilterManager& filter_manager) -> bool {
ASSERT(filter_ != nullptr);
filter_manager.addAcceptFilter(nullptr, std::move(filter_));
dispatcher_->exit();
return true;
}));
Expand All @@ -82,7 +83,8 @@ void ListenerFilterWithDataFuzzer::disconnect() {
void ListenerFilterWithDataFuzzer::fuzz(
Network::ListenerFilterPtr filter,
const test::extensions::filters::listener::FilterFuzzWithDataTestCase& input) {
connect(std::move(filter));
filter_ = std::move(filter);
connect();
for (int i = 0; i < input.data_size(); i++) {
std::string data(input.data(i).begin(), input.data(i).end());
write(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,18 @@ class ListenerFilterWithDataFuzzer : public Network::ListenerConfig,
return filter_chain_.get();
}

void fuzz(Network::ListenerFilterPtr filter,
const test::extensions::filters::listener::FilterFuzzWithDataTestCase& input);

private:
void write(const std::string& s) {
Buffer::OwnedImpl buf(s);
conn_->write(buf, false);
}

void connect(Network::ListenerFilterPtr filter);
void connect();
void disconnect();

void fuzz(Network::ListenerFilterPtr filter,
const test::extensions::filters::listener::FilterFuzzWithDataTestCase& input);

private:
testing::NiceMock<Runtime::MockLoader> runtime_;
Stats::TestUtil::TestStore stats_store_;
Api::ApiPtr api_;
Expand All @@ -105,6 +105,7 @@ class ListenerFilterWithDataFuzzer : public Network::ListenerConfig,
std::vector<Network::ListenSocketFactoryPtr> socket_factories_;
Network::NopConnectionBalancerImpl connection_balancer_;
Network::ConnectionHandlerPtr connection_handler_;
Network::ListenerFilterPtr filter_{nullptr};
Network::MockFilterChainFactory factory_;
Network::ClientConnectionPtr conn_;
NiceMock<Network::MockConnectionCallbacks> connection_callbacks_;
Expand Down

0 comments on commit 2f6f60d

Please sign in to comment.