From 5a523b22c56b510d624626f347ed5b2ab0bb8f52 Mon Sep 17 00:00:00 2001 From: re2zero Date: Thu, 28 May 2026 17:47:32 +0800 Subject: [PATCH] fix(lock): sanitize WAYLAND_DISPLAY in lockfile path When WAYLAND_DISPLAY contains a slash (e.g. wl/wayland-1), the lockfile path would include a subdirectory component that may not exist, causing open() to fail. Replace '/' with '-' in WAYLAND_DISPLAY before constructing the lockfile path. Fixes #188 --- lock.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lock.c b/lock.c index ff4cda3..5e165f9 100644 --- a/lock.c +++ b/lock.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include "lock.h" @@ -27,7 +28,17 @@ bool get_lockfile_path(char path[MAX_PATH_SIZE]) { return false; } - if (snprintf(path, MAX_PATH_SIZE, "%s/slurp-%s.lock", runtime_dir, display) >= MAX_PATH_SIZE) { + // Replace '/' with '-' in display to avoid creating subdirectories + char sanitized_display[256]; + strncpy(sanitized_display, display, sizeof(sanitized_display) - 1); + sanitized_display[sizeof(sanitized_display) - 1] = '\0'; + for (char *p = sanitized_display; *p; p++) { + if (*p == '/') { + *p = '-'; + } + } + + if (snprintf(path, MAX_PATH_SIZE, "%s/slurp-%s.lock", runtime_dir, sanitized_display) >= MAX_PATH_SIZE) { fprintf(stderr, "lockfile path was too long\n"); return false; } @@ -51,6 +62,4 @@ bool acquire_lock() { return false; } return true; -} - - +} \ No newline at end of file