* files.c (do_writeout): Also abort on writing a backup

file when its owner doesn't match the edited file.



git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4491 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
Chris Allegretta
2010-04-07 05:48:24 +00:00
parent cdb5b16198
commit 0d1381adf9
2 changed files with 13 additions and 2 deletions

View File

@@ -1519,6 +1519,7 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
char *backupname;
struct utimbuf filetime;
int copy_status;
struct stat backupst;
/* Save the original file's access and modification times. */
filetime.actime = openfile->current_stat->st_atime;
@@ -1588,6 +1589,15 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
sprintf(backupname, "%s~", realname);
}
if (stat(backupname, &backupst) != -1 &&
(backupst.st_uid != st.st_uid)) {
statusbar(_("Error writing backup file %s: Permission mismatch"), backupname,
strerror(errno));
free(backupname);
goto cleanup_and_exit;
}
/* Open the destination backup file. Before we write to it, we
* set its permissions, so no unauthorized person can read it as
* we write. */