diff options
author | Yossi Gottlieb <yossigo@gmail.com> | 2021-09-02 10:00:00 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-02 10:00:00 +0300 |
commit | c9931ddba53f43c291cb61b6976a91496976e2fd (patch) | |
tree | e90974aa6de41bda16ae331bf65cb6ad3cbb20b3 /deps | |
parent | f24c63a292e045d4b14b82b25981f00a95c1767a (diff) | |
download | redis-c9931ddba53f43c291cb61b6976a91496976e2fd.tar.gz |
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.
Diffstat (limited to 'deps')
-rw-r--r-- | deps/linenoise/linenoise.c | 3 |
1 files changed, 2 insertions, 1 deletions
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 <termios.h> #include <unistd.h> #include <stdlib.h> @@ -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); |