1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-06 01:33:12 +02:00

core: fix time-of-check/time-of-use race condition on theme files

Open theme files directly instead of probing them with access() first in
commands /theme apply, /theme rename and /theme info. The renamed file is
now created with O_CREAT | O_EXCL so an existing theme is never clobbered.
This commit is contained in:
Sébastien Helleu
2026-07-05 12:34:38 +02:00
parent f65591cb56
commit 3950041801
17 changed files with 79 additions and 177 deletions
+12 -1
View File
@@ -942,7 +942,7 @@ TEST(CoreTheme, Delete)
TEST(CoreTheme, Rename)
{
char *src_path, *dst_path;
char *src_path = NULL, *dst_path = NULL;
struct stat st;
FILE *file;
char buf[2048];
@@ -974,6 +974,17 @@ TEST(CoreTheme, Rename)
/* refuses target that already exists */
LONGS_EQUAL(WEECHAT_RC_OK, theme_save ("rn_dst"));
LONGS_EQUAL(WEECHAT_RC_ERROR, theme_rename ("rn_src", "rn_dst"));
/* the refused rename must not have clobbered the existing target */
dst_path = theme_user_file_path ("rn_dst");
CHECK(dst_path != NULL);
file = fopen (dst_path, "r");
CHECK(file != NULL);
len = fread (buf, 1, sizeof (buf) - 1, file);
buf[len] = '\0';
fclose (file);
CHECK(strstr (buf, "name = \"rn_dst\"") != NULL);
free (dst_path);
dst_path = NULL;
LONGS_EQUAL(WEECHAT_RC_OK, theme_delete ("rn_dst"));
/* happy path: rename moves the file and rewrites the [info] name */