Skip to content

Commit

Permalink
Use fchmod() to prevent possible race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
ldilley committed Oct 16, 2023
1 parent 5f92662 commit 5cfdcfb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/linenoise/linenoise.c
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,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);
Expand Down

0 comments on commit 5cfdcfb

Please sign in to comment.