nano

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

commit b30522463ae38015cfbc5c78ad7ae64591c73ac5
parent 5449d1e6a523e0ae53f3a45d35b390f9a3b4dab3
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Mon, 25 May 2020 12:22:15 +0200

files: do not append but truncate when allowing insecure backups

When deleting an existing backup file failed, we do not want to
append to this file, but want instead to overwrite it (when the
user has put 'set allow_insecure_backup' in their nanorc file).

Also, when using O_EXCL (in the normal, secure case), O_APPEND
is pointless, because the file will be created and thus empty.

This fixes https://savannah.gnu.org/bugs/?58439.

Bug existed since version 2.2.5, commit 461519cc.

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

diff --git a/src/files.c b/src/files.c @@ -1671,9 +1671,9 @@ bool write_file(const char *name, FILE *thefile, bool tmp, } if (ISSET(INSECURE_BACKUP)) - backup_cflags = O_WRONLY | O_CREAT | O_APPEND; + backup_cflags = O_WRONLY | O_CREAT | O_TRUNC; else - backup_cflags = O_WRONLY | O_CREAT | O_EXCL | O_APPEND; + backup_cflags = O_WRONLY | O_CREAT | O_EXCL; backup_fd = open(backupname, backup_cflags, RW_FOR_ALL);