Fix potential nullptr deref in Spicy plugin runtime

If we added a file but the other side of the connection had already run
into a protocol violation and shut down we could previously have
dereferenced a null cookie. This patch fixes the code so it now throws
in such scenarios.
This commit is contained in:
Benjamin Bannier 2024-11-04 16:15:09 +01:00
parent 0028ba320d
commit 93c201df57

View file

@ -285,11 +285,13 @@ void rt::debug(const Cookie& cookie, const std::string& msg) {
inline rt::cookie::FileStateStack* _file_state_stack(rt::Cookie* cookie) {
auto _ = hilti::rt::profiler::start("zeek/rt/file_state_stack");
if ( cookie ) {
if ( auto c = cookie->protocol )
return c->is_orig ? &c->fstate_orig : &c->fstate_resp;
else if ( auto f = cookie->file )
return &f->fstate;
else
}
throw rt::ValueUnavailable("no current connection or file available");
}