From 05db7dfd7fc261e0195e54f8a6d655d4f370e70f Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 10 Mar 2024 17:16:32 +0000 Subject: [PATCH] lib: refuse to read inaccessible themes fixes #1 --- libhyprcursor/hyprcursor.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/libhyprcursor/hyprcursor.cpp b/libhyprcursor/hyprcursor.cpp index 89913a7..eb33f28 100644 --- a/libhyprcursor/hyprcursor.cpp +++ b/libhyprcursor/hyprcursor.cpp @@ -26,6 +26,20 @@ static std::string themeNameFromEnv() { return std::string{ENV}; } +static bool themeAccessible(const std::string& path) { + try { + if (!std::filesystem::exists(path + "/manifest.hl")) + return false; + + const auto MANIFESTSTATUS = std::filesystem::status(path + "/manifest.hl"); + if ((MANIFESTSTATUS.permissions() & std::filesystem::perms::others_read) == std::filesystem::perms::none) + return false; + + } catch (std::exception& e) { return false; } + + return true; +} + static std::string getFirstTheme() { // try user directories first @@ -112,6 +126,9 @@ static std::string getFullPathForThemeName(const std::string& name) { if (!name.empty() && themeDir.path().stem().string() != name) continue; + if (!themeAccessible(themeDir.path().string())) + continue; + const auto MANIFESTPATH = themeDir.path().string() + "/manifest.hl"; if (std::filesystem::exists(MANIFESTPATH)) @@ -497,6 +514,9 @@ General std::optional CHyprcursorImplementation::loadTheme() { + if (!themeAccessible(themeFullDir)) + return "Theme inaccessible"; + currentTheme = &theme; // load manifest