Resolves: #1177155 - do not use closed file descriptor when setting backup's timestamp

This commit is contained in:
Kamil Dudka 2015-01-05 14:21:03 +01:00
parent 96bc512fd3
commit b07687ce0d
2 changed files with 38 additions and 6 deletions

View File

@ -7,8 +7,8 @@ Subject: [PATCH 3/3] use futimens() if available, instead of utime()
config.h.in | 3 +++
configure | 2 +-
configure.ac | 2 +-
src/files.c | 26 +++++++++++++++++++++++++-
4 files changed, 30 insertions(+), 3 deletions(-)
src/files.c | 48 ++++++++++++++++++++++++++++++++++++------------
4 files changed, 41 insertions(+), 14 deletions(-)
diff --git a/config.h.in b/config.h.in
index 52e13f1..cb17b29 100644
@ -84,16 +84,45 @@ index 99cc1b8..9a1bdcc 100644
/* Write a file out to disk. If f_open isn't NULL, we assume that it is
* a stream associated with the file, and we don't try to open it
* ourselves. If tmp is TRUE, we set the umask to disallow anyone else
@@ -1928,7 +1951,8 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
}
@@ -1917,18 +1940,9 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
fprintf(stderr, "Backing up %s to %s\n", realname, backupname);
#endif
/* And set its metadata. */
- /* Copy the file. */
- copy_status = copy_file(f, backup_file);
-
- if (copy_status != 0) {
- statusbar(_("Error reading %s: %s"), realname,
- strerror(errno));
- beep();
- goto cleanup_and_exit;
- }
-
- /* And set its metadata. */
- if (utime(backupname, &filetime) == -1 && !ISSET(INSECURE_BACKUP)) {
+ /* Set backup's file metadata. */
+ if (utime_wrap(backup_fd, backupname, &filetime) == -1
+ && !ISSET(INSECURE_BACKUP)) {
if (prompt_failed_backupwrite(backupname))
goto skip_backup;
statusbar(_("Error writing backup file %s: %s"), backupname,
@@ -1940,6 +1954,16 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
goto cleanup_and_exit;
}
+ /* Copy the file. */
+ copy_status = copy_file(f, backup_file);
+
+ if (copy_status != 0) {
+ statusbar(_("Error reading %s: %s"), realname,
+ strerror(errno));
+ beep();
+ goto cleanup_and_exit;
+ }
+
free(backupname);
}
--
1.7.4

View File

@ -1,7 +1,7 @@
Summary: A small text editor
Name: nano
Version: 2.3.6
Release: 2%{?dist}
Release: 3%{?dist}
License: GPLv3+
Group: Applications/Editors
URL: http://www.nano-editor.org
@ -90,6 +90,9 @@ exit 0
%{_datadir}/nano
%changelog
* Mon Jan 05 2015 Kamil Dudka <kdudka@redhat.com> - 2.3.6-3
- do not use closed file descriptor when setting backup's timestamp (#1177155)
* Sun Aug 17 2014 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 2.3.6-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_22_Mass_Rebuild