From 246b42b63570c13479836b6862c83c423ed7ee7a Mon Sep 17 00:00:00 2001 From: Itamar Date: Fri, 18 Feb 2022 17:21:58 +0200 Subject: [PATCH] LibGUI: Guard against use-after-free in Clipboard::the() We now make sure that a VERIFY will fail if Clipboard::the() is called after the destruction of its static-local variables. --- Userland/Libraries/LibGUI/Clipboard.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Userland/Libraries/LibGUI/Clipboard.cpp b/Userland/Libraries/LibGUI/Clipboard.cpp index 7038c9cfaa..9e1cb1a287 100644 --- a/Userland/Libraries/LibGUI/Clipboard.cpp +++ b/Userland/Libraries/LibGUI/Clipboard.cpp @@ -44,6 +44,12 @@ void Clipboard::initialize(Badge) Clipboard& Clipboard::the() { + static bool s_destructed = false; + static ScopeGuard destructed_guard([] { + s_destructed = true; + }); + VERIFY(!s_destructed); // Catch use-after-free + static Clipboard s_the; return s_the; }