aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorVaxry <[email protected]>2024-04-28 20:06:40 +0100
committerVaxry <[email protected]>2024-04-28 20:06:40 +0100
commitf7815dab42ee570c38bd7ae85a4f2a6e36803809 (patch)
tree25cb98f7fb5f23a7bc1a2628bf4f3b249e1881ba
parentb164e67d8b1f12420ec44a1c837af7923559ccf2 (diff)
downloadHyprland-f7815dab42ee570c38bd7ae85a4f2a6e36803809.tar.gz
Hyprland-f7815dab42ee570c38bd7ae85a4f2a6e36803809.zip
compositor: more fs safety around tmp directories
HIS now includes a random bit, and hyprland will bail if /tmp/hypr is not a directory or if /tmp/hypr/his exists
-rw-r--r--hyprctl/main.cpp2
-rw-r--r--src/Compositor.cpp21
2 files changed, 20 insertions, 3 deletions
diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp
index 3337cbff..9b2c2fd2 100644
--- a/hyprctl/main.cpp
+++ b/hyprctl/main.cpp
@@ -51,7 +51,7 @@ std::vector<SInstanceData> instances() {
data->id = data->id.substr(data->id.find_last_of('/') + 1, data->id.find(".lock") - data->id.find_last_of('/') - 1);
try {
- data->time = std::stoull(data->id.substr(data->id.find_first_of('_') + 1));
+ data->time = std::stoull(data->id.substr(data->id.find_first_of('_') + 1, data->id.find_last_of('_') - (data->id.find_first_of('_') + 1)));
} catch (std::exception& e) { continue; }
// read file
diff --git a/src/Compositor.cpp b/src/Compositor.cpp
index 8e333ebe..d252dda2 100644
--- a/src/Compositor.cpp
+++ b/src/Compositor.cpp
@@ -62,15 +62,32 @@ void handleUserSignal(int sig) {
CCompositor::CCompositor() {
m_iHyprlandPID = getpid();
- m_szInstanceSignature = GIT_COMMIT_HASH + std::string("_") + std::to_string(time(NULL));
+ std::random_device dev;
+ std::mt19937 engine(dev());
+ std::uniform_int_distribution<> distribution(0, INT32_MAX);
+
+ m_szInstanceSignature = GIT_COMMIT_HASH + std::string("_") + std::to_string(time(NULL)) + "_" + std::to_string(distribution(engine));
setenv("HYPRLAND_INSTANCE_SIGNATURE", m_szInstanceSignature.c_str(), true);
if (!std::filesystem::exists("/tmp/hypr"))
mkdir("/tmp/hypr", S_IRWXU | S_IRWXG | S_IRWXO | S_ISVTX);
+ else if (!std::filesystem::is_directory("/tmp/hypr")) {
+ std::cout << "Bailing out, /tmp/hypr is not a directory\n";
+ return;
+ }
const auto INSTANCEPATH = "/tmp/hypr/" + m_szInstanceSignature;
- mkdir(INSTANCEPATH.c_str(), S_IRWXU | S_IRWXG);
+
+ if (std::filesystem::exists(INSTANCEPATH)) {
+ std::cout << "Bailing out, /tmp/hypr/$HIS exists??\n";
+ return;
+ }
+
+ if (mkdir(INSTANCEPATH.c_str(), S_IRWXU) < 0) {
+ std::cout << "Bailing out, couldn't create /tmp/hypr/$HIS\n";
+ return;
+ }
Debug::init(m_szInstanceSignature);