diff --git a/src/IPAddr.cc b/src/IPAddr.cc index 97beebcffa..50b906526e 100644 --- a/src/IPAddr.cc +++ b/src/IPAddr.cc @@ -44,12 +44,26 @@ ConnKey::ConnKey(const IPAddr& src, const IPAddr& dst, uint16_t src_port, } } -detail::ConnKey::ConnKey(const ConnTuple& id) +ConnKey::ConnKey(const ConnTuple& id) : ConnKey(id.src_addr, id.dst_addr, id.src_port, id.dst_port, id.proto, id.is_one_way) { } +ConnKey& ConnKey::operator=(const ConnKey& rhs) + { + if ( this == &rhs ) + return *this; + + memcpy(&ip1, &rhs.ip1, sizeof(in6_addr)); + memcpy(&ip2, &rhs.ip2, sizeof(in6_addr)); + port1 = rhs.port1; + port2 = rhs.port2; + transport = rhs.transport; + + return *this; + } + } // namespace detail IPAddr::IPAddr(const String& s) diff --git a/src/IPAddr.h b/src/IPAddr.h index fbabc3227c..9dbf6502ab 100644 --- a/src/IPAddr.h +++ b/src/IPAddr.h @@ -4,7 +4,7 @@ #include #include -#include +#include #include #include @@ -43,13 +43,7 @@ struct ConnKey { bool operator>=(const ConnKey& rhs) const { return memcmp(this, &rhs, sizeof(ConnKey)) >= 0; } bool operator>(const ConnKey& rhs) const { return memcmp(this, &rhs, sizeof(ConnKey)) > 0; } - ConnKey& operator=(const ConnKey& rhs) - { - if ( this != &rhs ) - memcpy(this, &rhs, sizeof(ConnKey)); - - return *this; - } + ConnKey& operator=(const ConnKey& rhs); }; using ConnIDKey [[deprecated("Remove in v5.1. Use zeek::detail::ConnKey.")]] = ConnKey; diff --git a/src/session/Key.cc b/src/session/Key.cc index 96035e31d6..6044f493f8 100644 --- a/src/session/Key.cc +++ b/src/session/Key.cc @@ -7,8 +7,11 @@ namespace zeek::session::detail { Key::Key(const void* session, size_t size, bool copy) : size(size) { data = reinterpret_cast(session); + if ( copy ) CopyData(); + + copied = copy; } Key::Key(Key&& rhs)