From c4913662e111e87e3c0784e607f94fdff7f1c58a Mon Sep 17 00:00:00 2001 From: Tom Englund Date: Mon, 15 Jul 2024 20:01:48 +0200 Subject: [PATCH] Aquamarine headers for no pch build and a heap use after free (#6892) * build: add includes for no precompiled headers missing includes for no precompiled headers/lto usage. * math: avoid heap use after free on destruction of hyprland transforms gets double freed in aquamarine and hyprland, instead of a global use a function-local static variable which avoids any issues related to initialization order across different translation units. --- src/Compositor.cpp | 2 + src/config/ConfigManager.cpp | 1 + src/debug/CrashReporter.cpp | 1 + src/debug/HyprCtl.cpp | 2 + src/devices/IKeyboard.cpp | 1 + src/helpers/Format.cpp | 1 + src/helpers/math/Math.cpp | 115 ++++-------------------------- src/helpers/sync/SyncTimeline.hpp | 1 + src/managers/CursorManager.hpp | 2 + src/managers/PointerManager.hpp | 1 + src/managers/ProtocolManager.cpp | 4 ++ src/plugins/PluginAPI.cpp | 1 + src/protocols/LinuxDMABUF.hpp | 2 + src/protocols/Screencopy.hpp | 1 + src/protocols/core/Compositor.cpp | 1 + src/protocols/types/WLBuffer.cpp | 1 + src/render/OpenGL.cpp | 1 + src/render/Renderbuffer.cpp | 2 + src/render/Renderbuffer.hpp | 3 + src/xwayland/Server.cpp | 1 + 20 files changed, 44 insertions(+), 100 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 41d6d848..7fdb906c 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include "debug/HyprCtl.hpp" #include "debug/CrashReporter.hpp" @@ -24,6 +25,7 @@ #include "protocols/core/Compositor.hpp" #include "protocols/core/Subcompositor.hpp" #include "desktop/LayerSurface.hpp" +#include "render/Renderer.hpp" #include "xwayland/XWayland.hpp" #include diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 1681dea1..a5f18693 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -24,6 +24,7 @@ #include #include #include +#include using namespace Hyprutils::String; extern "C" char** environ; diff --git a/src/debug/CrashReporter.cpp b/src/debug/CrashReporter.cpp index ce1a92ba..c25212fe 100644 --- a/src/debug/CrashReporter.cpp +++ b/src/debug/CrashReporter.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "../plugins/PluginSystem.hpp" #include "../signal-safe.hpp" diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 76ef8218..61c3e4b0 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include diff --git a/src/devices/IKeyboard.cpp b/src/devices/IKeyboard.cpp index 3e69bfd8..284a8295 100644 --- a/src/devices/IKeyboard.cpp +++ b/src/devices/IKeyboard.cpp @@ -3,6 +3,7 @@ #include "../helpers/varlist/VarList.hpp" #include "../managers/input/InputManager.hpp" #include "../managers/SeatManager.hpp" +#include "../config/ConfigManager.hpp" #include #include #include diff --git a/src/helpers/Format.cpp b/src/helpers/Format.cpp index 8d080322..afc8b1c5 100644 --- a/src/helpers/Format.cpp +++ b/src/helpers/Format.cpp @@ -4,6 +4,7 @@ #include "debug/Log.hpp" #include "../macros.hpp" #include +#include /* DRM formats are LE, while OGL is BE. The two primary formats diff --git a/src/helpers/math/Math.cpp b/src/helpers/math/Math.cpp index f8b61bce..fccfd636 100644 --- a/src/helpers/math/Math.cpp +++ b/src/helpers/math/Math.cpp @@ -70,113 +70,28 @@ void matrixRotate(float mat[9], float rad) { matrixMultiply(mat, mat, rotate); } -std::unordered_map> transforms = { - {HYPRUTILS_TRANSFORM_NORMAL, - { - 1.0f, - 0.0f, - 0.0f, - 0.0f, - 1.0f, - 0.0f, - 0.0f, - 0.0f, - 1.0f, - }}, - {HYPRUTILS_TRANSFORM_90, - { - 0.0f, - 1.0f, - 0.0f, - -1.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 1.0f, - }}, - {HYPRUTILS_TRANSFORM_180, - { - -1.0f, - 0.0f, - 0.0f, - 0.0f, - -1.0f, - 0.0f, - 0.0f, - 0.0f, - 1.0f, - }}, - {HYPRUTILS_TRANSFORM_270, - { - 0.0f, - -1.0f, - 0.0f, - 1.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 1.0f, - }}, - {HYPRUTILS_TRANSFORM_FLIPPED, - { - -1.0f, - 0.0f, - 0.0f, - 0.0f, - 1.0f, - 0.0f, - 0.0f, - 0.0f, - 1.0f, - }}, - {HYPRUTILS_TRANSFORM_FLIPPED_90, - { - 0.0f, - 1.0f, - 0.0f, - 1.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 1.0f, - }}, - {HYPRUTILS_TRANSFORM_FLIPPED_180, - { - 1.0f, - 0.0f, - 0.0f, - 0.0f, - -1.0f, - 0.0f, - 0.0f, - 0.0f, - 1.0f, - }}, - {HYPRUTILS_TRANSFORM_FLIPPED_270, - { - 0.0f, - -1.0f, - 0.0f, - -1.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 1.0f, - }}, -}; +const std::unordered_map>& getTransforms() { + static std::unordered_map> transforms = { + {HYPRUTILS_TRANSFORM_NORMAL, {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}}, + {HYPRUTILS_TRANSFORM_90, {0.0f, 1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}}, + {HYPRUTILS_TRANSFORM_180, {-1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f}}, + {HYPRUTILS_TRANSFORM_270, {0.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}}, + {HYPRUTILS_TRANSFORM_FLIPPED, {-1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}}, + {HYPRUTILS_TRANSFORM_FLIPPED_90, {0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}}, + {HYPRUTILS_TRANSFORM_FLIPPED_180, {1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f}}, + {HYPRUTILS_TRANSFORM_FLIPPED_270, {0.0f, -1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}}, + }; + return transforms; +} void matrixTransform(float mat[9], eTransform transform) { - matrixMultiply(mat, mat, transforms.at(transform).data()); + matrixMultiply(mat, mat, getTransforms().at(transform).data()); } void matrixProjection(float mat[9], int width, int height, eTransform transform) { memset(mat, 0, sizeof(*mat) * 9); - const float* t = transforms.at(transform).data(); + const float* t = getTransforms().at(transform).data(); float x = 2.0f / width; float y = 2.0f / height; diff --git a/src/helpers/sync/SyncTimeline.hpp b/src/helpers/sync/SyncTimeline.hpp index 4bb8019b..3d868a95 100644 --- a/src/helpers/sync/SyncTimeline.hpp +++ b/src/helpers/sync/SyncTimeline.hpp @@ -4,6 +4,7 @@ #include #include #include +#include "../memory/Memory.hpp" /* Hyprland synchronization timelines are based on the wlroots' ones, which diff --git a/src/managers/CursorManager.hpp b/src/managers/CursorManager.hpp index a2e8af21..4324dfb4 100644 --- a/src/managers/CursorManager.hpp +++ b/src/managers/CursorManager.hpp @@ -6,6 +6,8 @@ #include "../includes.hpp" #include "../helpers/math/Math.hpp" #include "../helpers/memory/Memory.hpp" +#include "../macros.hpp" +#include class CWLSurface; diff --git a/src/managers/PointerManager.hpp b/src/managers/PointerManager.hpp index 6846c382..cf4f1a94 100644 --- a/src/managers/PointerManager.hpp +++ b/src/managers/PointerManager.hpp @@ -6,6 +6,7 @@ #include "../helpers/math/Math.hpp" #include "../helpers/math/Math.hpp" #include "../desktop/WLSurface.hpp" +#include "../helpers/sync/SyncTimeline.hpp" #include class CMonitor; diff --git a/src/managers/ProtocolManager.cpp b/src/managers/ProtocolManager.cpp index 3006468f..387cac8f 100644 --- a/src/managers/ProtocolManager.cpp +++ b/src/managers/ProtocolManager.cpp @@ -49,6 +49,10 @@ #include "../helpers/Monitor.hpp" #include "../render/Renderer.hpp" +#include "../Compositor.hpp" + +#include +#include void CProtocolManager::onMonitorModeChange(CMonitor* pMonitor) { const bool ISMIRROR = pMonitor->isMirror(); diff --git a/src/plugins/PluginAPI.cpp b/src/plugins/PluginAPI.cpp index 6e09ba2c..098e3f12 100644 --- a/src/plugins/PluginAPI.cpp +++ b/src/plugins/PluginAPI.cpp @@ -2,6 +2,7 @@ #include "../Compositor.hpp" #include "../debug/HyprCtl.hpp" #include +#include #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) #include diff --git a/src/protocols/LinuxDMABUF.hpp b/src/protocols/LinuxDMABUF.hpp index 7f252588..449b4ac9 100644 --- a/src/protocols/LinuxDMABUF.hpp +++ b/src/protocols/LinuxDMABUF.hpp @@ -7,6 +7,8 @@ #include "wayland.hpp" #include "linux-dmabuf-v1.hpp" #include "../helpers/signal/Signal.hpp" +#include "../helpers/Format.hpp" +#include "../helpers/Monitor.hpp" #include class CDMABuffer; diff --git a/src/protocols/Screencopy.hpp b/src/protocols/Screencopy.hpp index 063068b5..4999773b 100644 --- a/src/protocols/Screencopy.hpp +++ b/src/protocols/Screencopy.hpp @@ -8,6 +8,7 @@ #include "../managers/HookSystemManager.hpp" #include "../helpers/Timer.hpp" #include "../managers/eventLoop/EventLoopTimer.hpp" +#include class CMonitor; class IHLBuffer; diff --git a/src/protocols/core/Compositor.cpp b/src/protocols/core/Compositor.cpp index 6fad79cc..a038bf08 100644 --- a/src/protocols/core/Compositor.cpp +++ b/src/protocols/core/Compositor.cpp @@ -8,6 +8,7 @@ #include "../../helpers/Monitor.hpp" #include "../PresentationTime.hpp" #include "../DRMSyncobj.hpp" +#include "../../render/Renderer.hpp" #define LOGM PROTO::compositor->protoLog diff --git a/src/protocols/types/WLBuffer.cpp b/src/protocols/types/WLBuffer.cpp index 7034dfc7..cc24546d 100644 --- a/src/protocols/types/WLBuffer.cpp +++ b/src/protocols/types/WLBuffer.cpp @@ -3,6 +3,7 @@ #include "../core/Compositor.hpp" #include "../DRMSyncobj.hpp" #include "../../helpers/sync/SyncTimeline.hpp" +#include "../../Compositor.hpp" #include CWLBufferResource::CWLBufferResource(SP resource_) : resource(resource_) { diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index be449dfe..7870bf6d 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -11,6 +11,7 @@ #include #include #include +#include inline void loadGLProc(void* pProc, const char* name) { void* proc = (void*)eglGetProcAddress(name); diff --git a/src/render/Renderbuffer.cpp b/src/render/Renderbuffer.cpp index 57f4fbd2..58ed88d6 100644 --- a/src/render/Renderbuffer.cpp +++ b/src/render/Renderbuffer.cpp @@ -2,6 +2,8 @@ #include "OpenGL.hpp" #include "../Compositor.hpp" #include "../protocols/types/Buffer.hpp" +#include +#include #include diff --git a/src/render/Renderbuffer.hpp b/src/render/Renderbuffer.hpp index f8155087..e6bfa909 100644 --- a/src/render/Renderbuffer.hpp +++ b/src/render/Renderbuffer.hpp @@ -1,5 +1,8 @@ #pragma once +#include "../helpers/signal/Signal.hpp" +#include "../helpers/memory/Memory.hpp" +#include "../helpers/WLListener.hpp" #include "Framebuffer.hpp" #include diff --git a/src/xwayland/Server.cpp b/src/xwayland/Server.cpp index 1d8b0cf5..3f4e7b43 100644 --- a/src/xwayland/Server.cpp +++ b/src/xwayland/Server.cpp @@ -18,6 +18,7 @@ #include #include #include +#include // TODO: cleanup static bool set_cloexec(int fd, bool cloexec) {