Unverified Commit c9931ddb authored by Yossi Gottlieb's avatar Yossi Gottlieb Committed by GitHub
Browse files

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.
parent f24c63a2
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment