nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit f9fe9a7d57cc289a26150e3e49943e50137cefdf
parent 8bf5e58f37f79240c65c5412f4b7d1b823f775fa
Author: Benno Schulenberg <bensberg@justemail.net>
Date:   Sat, 21 May 2016 13:50:14 +0200

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.

Diffstat:
Msrc/files.c | 6+++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/files.c b/src/files.c @@ -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 * only if the file has not been modified by someone else since nano * opened it. */ - if (ISSET(BACKUP_FILE) && !tmp && realexists && ((append != OVERWRITE || - openfile->mark_set) || (openfile->current_stat && - openfile->current_stat->st_mtime == st.st_mtime))) { + if (ISSET(BACKUP_FILE) && !tmp && realexists && openfile->current_stat && + (append != OVERWRITE || openfile->mark_set || + openfile->current_stat->st_mtime == st.st_mtime)) { int backup_fd; FILE *backup_file; char *backupname;