Commit f9fe9a7d authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

backups: take an unlikely condition into account

Between the first stat (that sets 'realexists') and the second stat
(directly after), the file might have disappeared, which would mean
that current_stat would be NULL.  Prevent dereferencing this further
down.
Showing with 3 additions and 3 deletions
+3 -3
...@@ -1801,9 +1801,9 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type ...@@ -1801,9 +1801,9 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
* aren't appending, prepending, or writing a selection, we backup * aren't appending, prepending, or writing a selection, we backup
* only if the file has not been modified by someone else since nano * only if the file has not been modified by someone else since nano
* opened it. */ * opened it. */
if (ISSET(BACKUP_FILE) && !tmp && realexists && ((append != OVERWRITE || if (ISSET(BACKUP_FILE) && !tmp && realexists && openfile->current_stat &&
openfile->mark_set) || (openfile->current_stat && (append != OVERWRITE || openfile->mark_set ||
openfile->current_stat->st_mtime == st.st_mtime))) { openfile->current_stat->st_mtime == st.st_mtime)) {
int backup_fd; int backup_fd;
FILE *backup_file; FILE *backup_file;
char *backupname; char *backupname;
......
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