From c9931ddba53f43c291cb61b6976a91496976e2fd Mon Sep 17 00:00:00 2001 From: Yossi Gottlieb Date: Thu, 2 Sep 2021 10:00:00 +0300 Subject: Use fchmod to update command history file. (#9447) This is considered a safer approach as it prevents a race condition that could lead to chmod executed on a different file. Not a major risk, but CodeQL alerted this so it makes sense to fix. --- deps/linenoise/linenoise.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'deps') diff --git a/deps/linenoise/linenoise.c b/deps/linenoise/linenoise.c index ccf5c5548..b0a847045 100644 --- a/deps/linenoise/linenoise.c +++ b/deps/linenoise/linenoise.c @@ -103,6 +103,7 @@ * */ +#define _BSD_SOURCE /* For fchmod() */ #include #include #include @@ -1194,7 +1195,7 @@ int linenoiseHistorySave(const char *filename) { fp = fopen(filename,"w"); umask(old_umask); if (fp == NULL) return -1; - chmod(filename,S_IRUSR|S_IWUSR); + fchmod(fileno(fp),S_IRUSR|S_IWUSR); for (j = 0; j < history_len; j++) fprintf(fp,"%s\n",history[j]); fclose(fp); -- cgit v1.2.1