From f0e023bff2f2a25ffe5ed3166f55f7274d17c6bc Mon Sep 17 00:00:00 2001 From: Tom Englund Date: Fri, 25 Oct 2024 12:26:48 +0200 Subject: security-context: avoid UB in C macro (#8229) to safely use wl_container_of with a class the class has to be no virtual functions, no inheritance, and uniform access control (e.g all public) work around this by putting this into a destroywrapper struct. --- src/protocols/SecurityContext.hpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/protocols/SecurityContext.hpp') diff --git a/src/protocols/SecurityContext.hpp b/src/protocols/SecurityContext.hpp index 76313bcf..63f58bde 100644 --- a/src/protocols/SecurityContext.hpp +++ b/src/protocols/SecurityContext.hpp @@ -37,14 +37,20 @@ class CSecurityContextManagerResource { SP resource; }; +class CSecurityContextSandboxedClient; +struct CSecurityContextSandboxedClientDestroyWrapper { + wl_listener listener; + CSecurityContextSandboxedClient* parent = nullptr; +}; + class CSecurityContextSandboxedClient { public: static SP create(int clientFD); ~CSecurityContextSandboxedClient(); - void onDestroy(); + void onDestroy(); - wl_listener destroyListener; + CSecurityContextSandboxedClientDestroyWrapper destroyListener; private: CSecurityContextSandboxedClient(int clientFD_); @@ -81,4 +87,4 @@ class CSecurityContextProtocol : public IWaylandProtocol { namespace PROTO { inline UP securityContext; -}; \ No newline at end of file +}; -- cgit v1.2.3