diff --git a/src/spicy/cookie.h b/src/spicy/cookie.h index 6823dfc488..de9a80569a 100644 --- a/src/spicy/cookie.h +++ b/src/spicy/cookie.h @@ -7,6 +7,7 @@ #pragma once +#include #include #include #include @@ -14,6 +15,9 @@ #include #include +#include + +#include "zeek/Reporter.h" #include "zeek/Val.h" #include "zeek/analyzer/Analyzer.h" #include "zeek/analyzer/protocol/tcp/TCP.h" @@ -129,10 +133,25 @@ struct Cookie { Cookie(cookie::ProtocolAnalyzer&& c) : data(std::move(c)) { protocol = &data.protocol; } Cookie(cookie::FileAnalyzer&& c) : data(std::move(c)) { file = &data.file; } Cookie(cookie::PacketAnalyzer&& c) : data(std::move(c)) { packet = &data.packet; } - Cookie(Cookie&& other) noexcept : data(other.tag(), std::move(other.data)) { _initLike(other); } + + Cookie(Cookie&& other) noexcept + : data( + [&]() { + try { + return other.tag(); + } catch ( const std::exception& e ) { + auto type = hilti::rt::demangle(typeid(e).name()); + reporter->FatalError("terminating with uncaught exception of type %s: %s", type.c_str(), + e.what()); + } + }(), + std::move(other.data)) { + _initLike(other); + } + ~Cookie() { _delete(); } - Cookie& operator=(Cookie&& other) noexcept { + Cookie& operator=(Cookie&& other) noexcept try { if ( this == &other ) return *this; @@ -141,6 +160,9 @@ struct Cookie { new (&data) Data(tag(), std::move(other.data)); return *this; + } catch ( const std::exception& e ) { + auto type = hilti::rt::demangle(typeid(e).name()); + reporter->FatalError("terminating with uncaught exception of type %s: %s", type.c_str(), e.what()); } // Cache of values that can be expensive to compute.