mirror of
http://github.com/valkey-io/valkey
synced 2024-11-22 00:52:38 +00:00
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.
This commit is contained in:
parent
f24c63a292
commit
c9931ddba5
3
deps/linenoise/linenoise.c
vendored
3
deps/linenoise/linenoise.c
vendored
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user