From d97a578e4f2a05d6bf20e8f2498c3ca32d3ced5f Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Fri, 22 Sep 2023 18:07:00 +0200 Subject: [PATCH] Do not require cookie for `reject_protocol` during teardown. A user reported that they ran into a situation where a parse error caused an assertion failure in `reject_protocol`. printf debugging points to the `CookieSetter`s in the `try`/`catch` blocks during processing already clearing the cookie RAII-style; since their `catch` blocks already send an analyzer violation no further sending of one from `reject_protocol` is required. This patch replaces the assert in `reject_protocol` with a runtime check and an early return if the cookie is already cleared. --- src/spicy/runtime-support.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/spicy/runtime-support.cc b/src/spicy/runtime-support.cc index d23bb11a40..58fa96041c 100644 --- a/src/spicy/runtime-support.cc +++ b/src/spicy/runtime-support.cc @@ -453,7 +453,12 @@ void rt::confirm_protocol() { void rt::reject_protocol(const std::string& reason) { auto _ = hilti::rt::profiler::start("zeek/rt/reject_protocol"); auto cookie = static_cast(hilti::rt::context::cookie()); - assert(cookie); + + // We might be invoked during teardown when the cookie has already been + // cleared. These other code paths also take care of sending an analyzer + // violation to Zeek, so we can immediately return for such cases here. + if ( ! cookie ) + return; if ( auto x = cookie->protocol ) { auto tag = spicy_mgr->tagForProtocolAnalyzer(x->analyzer->GetAnalyzerTag());