From 869aca43929a14023940437199b7d70438738271 Mon Sep 17 00:00:00 2001 From: Chris Allegretta Date: Sun, 20 Dec 2009 05:46:35 +0000 Subject: [PATCH] 2009-12-20 Brian Szymanski * src/files.c (write_file): Check stat struct exists, and if not use just obtained stat data. Fixes Ubuntu bug 471568, "reproducible crash in nano on trying to save to a file different than the one specified on the command line". git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4467 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 5 +++++ src/files.c | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/ChangeLog b/ChangeLog index bc082bf2..6a98054a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-12-20 Brian Szymanski + * src/files.c (write_file): Check stat struct exists, and if not use just obtained stat data. + Fixes Ubuntu bug 471568, "reproducible crash in nano on trying to save to a file + different than the one specified on the command line". + 2009-12-15 Chris Allegretta * doc/nanorc.sample.in - Remove erroneous 'set suspendenable' as it's actually a key binding (e.g. 'bind M-Z suspendenable all') and not a settable flag. Fixes diff --git a/src/files.c b/src/files.c index 9b29a58e..1355d380 100644 --- a/src/files.c +++ b/src/files.c @@ -1499,6 +1499,13 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type * one). */ realexists = (stat(realname, &st) != -1); + /* if we have not stat()d this file before (say, the user just + * specified it interactively), use the info we just got from + * stat()ing or else we will chase null pointers when we do + * modtime checks, preserve file times, etc. during backup */ + if(openfile->current_stat == NULL) + openfile->current_stat = &st; + #ifndef NANO_TINY /* We backup only if the backup toggle is set, the file isn't * temporary, and the file already exists. Furthermore, if we -- 2.39.5