From ae33aa04136fd893fa5624a909547b2fba5668cd Mon Sep 17 00:00:00 2001 From: Evan Typanski Date: Mon, 11 Nov 2024 10:30:02 -0500 Subject: [PATCH] Fix nullptr deref in Spicy accept/decline input Seems like this is a continuation of #4006 --- src/spicy/manager.cc | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/spicy/manager.cc b/src/spicy/manager.cc index 4b1d32426c..6d6cd3f059 100644 --- a/src/spicy/manager.cc +++ b/src/spicy/manager.cc @@ -593,25 +593,25 @@ static ::TransportProto transport_protocol(const hilti::rt::Port port) { } static void hook_accept_input() { - auto cookie = static_cast(hilti::rt::context::cookie()); - assert(cookie); - - if ( auto x = cookie->protocol ) { - auto tag = spicy_mgr->tagForProtocolAnalyzer(x->analyzer->GetAnalyzerTag()); - SPICY_DEBUG(hilti::rt::fmt("confirming protocol %s", tag.AsString())); - return x->analyzer->AnalyzerConfirmation(tag); + if ( auto cookie = static_cast(hilti::rt::context::cookie()) ) { + if ( auto x = cookie->protocol ) { + auto tag = spicy_mgr->tagForProtocolAnalyzer(x->analyzer->GetAnalyzerTag()); + SPICY_DEBUG(hilti::rt::fmt("confirming protocol %s", tag.AsString())); + return x->analyzer->AnalyzerConfirmation(tag); + } } } static void hook_decline_input(const std::string& reason) { - auto cookie = static_cast(hilti::rt::context::cookie()); - assert(cookie); - - if ( auto x = cookie->protocol ) { - auto tag = spicy_mgr->tagForProtocolAnalyzer(x->analyzer->GetAnalyzerTag()); - SPICY_DEBUG(hilti::rt::fmt("rejecting protocol %s: %s", tag.AsString(), reason)); - return x->analyzer->AnalyzerViolation(reason.c_str(), nullptr, 0, tag); + if ( auto cookie = static_cast(hilti::rt::context::cookie()) ) { + if ( auto x = cookie->protocol ) { + auto tag = spicy_mgr->tagForProtocolAnalyzer(x->analyzer->GetAnalyzerTag()); + SPICY_DEBUG(hilti::rt::fmt("rejecting protocol %s: %s", tag.AsString(), reason)); + return x->analyzer->AnalyzerViolation(reason.c_str(), nullptr, 0, tag); + } } + else + SPICY_DEBUG(hilti::rt::fmt("attempting to reject protocol without cookie: %s", reason)); } void Manager::InitPostScript() {