From 6b56849c87c4817a691827ada92c35329c15ae9a Mon Sep 17 00:00:00 2001 From: Razvan Cojocaru Date: Wed, 7 Aug 2024 11:59:07 +0300 Subject: [PATCH] Add default virtual destructors to base classes with virtual functions Without this fix, the openvpn3-linux build is broken whenever a dependency enables -Wnon-virtual-dtor (which protobuf 27.3 currently does on Arch Linux). The openvpn3-linux build treats warnings as errors. Jira: OVPN3-1242 Signed-off-by: Razvan Cojocaru (cherry picked from commit 6217fa0e1a628b407e9ee1e12db28819462b981f) --- openvpn/buffer/bufcomplete.hpp | 3 ++- openvpn/buffer/buffer.hpp | 12 +++++++++++- openvpn/buffer/buflimit.hpp | 2 ++ openvpn/client/clilife.hpp | 2 ++ openvpn/client/cliproto.hpp | 2 ++ openvpn/client/remotelist.hpp | 6 ++++++ openvpn/ssl/proto.hpp | 2 ++ openvpn/transport/reconnect_notify.hpp | 2 ++ openvpn/transport/socket_protect.hpp | 2 ++ openvpn/tun/client/tunbase.hpp | 2 ++ 10 files changed, 33 insertions(+), 2 deletions(-) diff --git a/openvpn/buffer/bufcomplete.hpp b/openvpn/buffer/bufcomplete.hpp index 84df6148..23d633f1 100644 --- a/openvpn/buffer/bufcomplete.hpp +++ b/openvpn/buffer/bufcomplete.hpp @@ -32,8 +32,9 @@ namespace openvpn { class BufferComplete { public: - /* each advance/get method returns false if message is incomplete */ + virtual ~BufferComplete() = default; + /* each advance/get method returns false if message is incomplete */ bool advance(size_t size) { while (size) diff --git a/openvpn/buffer/buffer.hpp b/openvpn/buffer/buffer.hpp index 6d0a3810..36799716 100644 --- a/openvpn/buffer/buffer.hpp +++ b/openvpn/buffer/buffer.hpp @@ -214,7 +214,17 @@ class ConstBufferType { } - // const index into array + /** + * @brief Needed because this class has virtual member functions and is + * intended as a base class. + */ + virtual ~ConstBufferType() = default; + + /** + * @brief Const indexing operator for ConstBufferType. + * @param index Index of the element to access. + * @return Const reference to the element at the specified index. + */ const T &operator[](const size_t index) const { if (index >= size_) diff --git a/openvpn/buffer/buflimit.hpp b/openvpn/buffer/buflimit.hpp index 3ca65a9f..2e04b327 100644 --- a/openvpn/buffer/buflimit.hpp +++ b/openvpn/buffer/buflimit.hpp @@ -43,6 +43,8 @@ class BufferLimit reset(); } + virtual ~BufferLimit() = default; + void set_max(const T max_lines_arg, const T max_bytes_arg) { diff --git a/openvpn/client/clilife.hpp b/openvpn/client/clilife.hpp index d67274f3..f1e91ac1 100644 --- a/openvpn/client/clilife.hpp +++ b/openvpn/client/clilife.hpp @@ -34,6 +34,8 @@ class ClientLifeCycle : public RC public: struct NotifyCallback { + virtual ~NotifyCallback() = default; + virtual void cln_stop() = 0; virtual void cln_pause(const std::string &reason) = 0; virtual void cln_resume() = 0; diff --git a/openvpn/client/cliproto.hpp b/openvpn/client/cliproto.hpp index d65d4a70..734fce66 100644 --- a/openvpn/client/cliproto.hpp +++ b/openvpn/client/cliproto.hpp @@ -81,6 +81,8 @@ namespace openvpn::ClientProto { struct NotifyCallback { + virtual ~NotifyCallback() = default; + virtual void client_proto_terminate() = 0; virtual void client_proto_connected() { diff --git a/openvpn/client/remotelist.hpp b/openvpn/client/remotelist.hpp index beb1a56f..0ea609ef 100644 --- a/openvpn/client/remotelist.hpp +++ b/openvpn/client/remotelist.hpp @@ -112,6 +112,8 @@ class RemoteList : public RC { typedef RCPtr Ptr; + virtual ~ConnBlockFactory() = default; + virtual ConnBlock::Ptr new_conn_block(const OptionList::Ptr &opt) = 0; }; @@ -229,6 +231,8 @@ class RemoteList : public RC struct RemoteOverride { + virtual ~RemoteOverride() = default; + virtual Item::Ptr get() = 0; }; @@ -311,6 +315,8 @@ class RemoteList : public RC struct NotifyCallback { + virtual ~NotifyCallback() = default; + // client callback when resolve operation is complete virtual void bulk_resolve_done() = 0; }; diff --git a/openvpn/ssl/proto.hpp b/openvpn/ssl/proto.hpp index e3c12720..32997ca2 100644 --- a/openvpn/ssl/proto.hpp +++ b/openvpn/ssl/proto.hpp @@ -161,6 +161,8 @@ enum class ProtoContextCallbackInterface { public: + virtual ~ProtoContextCallbackInterface() = default; + /** * Sends out bytes to the network. */ diff --git a/openvpn/transport/reconnect_notify.hpp b/openvpn/transport/reconnect_notify.hpp index 5ce87912..5e821b6e 100644 --- a/openvpn/transport/reconnect_notify.hpp +++ b/openvpn/transport/reconnect_notify.hpp @@ -26,6 +26,8 @@ namespace openvpn { class ReconnectNotify { public: + virtual ~ReconnectNotify() = default; + // When a connection is close to timeout, the core will call this // method. If it returns false, the core will disconnect with a // CONNECTION_TIMEOUT event. If true, the core will enter a PAUSE diff --git a/openvpn/transport/socket_protect.hpp b/openvpn/transport/socket_protect.hpp index c03a9048..a5486efc 100644 --- a/openvpn/transport/socket_protect.hpp +++ b/openvpn/transport/socket_protect.hpp @@ -35,6 +35,8 @@ namespace openvpn { class BaseSocketProtect { public: + virtual ~BaseSocketProtect() = default; + virtual bool socket_protect(openvpn_io::detail::socket_type socket, IP::Addr endpoint) = 0; }; diff --git a/openvpn/tun/client/tunbase.hpp b/openvpn/tun/client/tunbase.hpp index efb12502..a8ff73ca 100644 --- a/openvpn/tun/client/tunbase.hpp +++ b/openvpn/tun/client/tunbase.hpp @@ -70,6 +70,8 @@ struct TunClient : public virtual RC // special events, and progress notifications. struct TunClientParent { + virtual ~TunClientParent() = default; + virtual void tun_recv(BufferAllocated &buf) = 0; virtual void tun_error(const Error::Type fatal_err, const std::string &err_text) = 0;