Prevent exception in noexcept function.

This commit is contained in:
Benjamin Bannier 2025-01-09 15:57:52 +01:00
parent 85ad6084e8
commit 3ea2d2760a

View file

@ -7,6 +7,7 @@
#pragma once #pragma once
#include <exception>
#include <memory> #include <memory>
#include <optional> #include <optional>
#include <string> #include <string>
@ -14,6 +15,9 @@
#include <variant> #include <variant>
#include <vector> #include <vector>
#include <hilti/rt/backtrace.h>
#include "zeek/Reporter.h"
#include "zeek/Val.h" #include "zeek/Val.h"
#include "zeek/analyzer/Analyzer.h" #include "zeek/analyzer/Analyzer.h"
#include "zeek/analyzer/protocol/tcp/TCP.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::ProtocolAnalyzer&& c) : data(std::move(c)) { protocol = &data.protocol; }
Cookie(cookie::FileAnalyzer&& c) : data(std::move(c)) { file = &data.file; } Cookie(cookie::FileAnalyzer&& c) : data(std::move(c)) { file = &data.file; }
Cookie(cookie::PacketAnalyzer&& c) : data(std::move(c)) { packet = &data.packet; } 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() { _delete(); }
Cookie& operator=(Cookie&& other) noexcept { Cookie& operator=(Cookie&& other) noexcept try {
if ( this == &other ) if ( this == &other )
return *this; return *this;
@ -141,6 +160,9 @@ struct Cookie {
new (&data) Data(tag(), std::move(other.data)); new (&data) Data(tag(), std::move(other.data));
return *this; 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. // Cache of values that can be expensive to compute.