]> git.cworth.org Git - tar/commitdiff
maybe_backup_file: Clear previously-set after_backup_name 508199
authorCarl Worth <cworth@cworth.org>
Tue, 4 Aug 2009 20:34:52 +0000 (13:34 -0700)
committerCarl Worth <cworth@cworth.org>
Wed, 5 Aug 2009 00:16:56 +0000 (17:16 -0700)
Without this, under various conditions, (including file_name being
a directory), maybe_backup_file would return true without having
done anything, nor having set after_backup_name. Then, if any
error was detected while extracting the member, (such as directory
already exists), the previously backed-up file would be restored,
potentially destroying user data.

This closes Debian bug #508199, with thanks to Eric Lammerts for
reporting it with a concise test case.

debian/changelog
src/misc.c

index 393a9e1a6567306073bf74a8077f9b9eeaecccec..68578c6ff059f16005b9fc3ad663210640a8f022 100644 (file)
@@ -1,3 +1,9 @@
+tar (1.22-3) UNRELEASED; urgency=low
+
+  * Avoid incorrectly restoring old backup file, closes: #508199
+
+ -- Carl Worth <cworth@cworth.org>  Tue, 04 Aug 2009 17:16:43 -0700
+
 tar (1.22-2) unstable; urgency=low
 
   * Add Carl Worth as an uploader.
index 951449eb0c0b035246b02fc50f27d7a7c7e1a49f..c400bcd5f14f0953c0d87b9982e589bb89d8da3d 100644 (file)
@@ -422,6 +422,10 @@ maybe_backup_file (const char *file_name, bool this_is_the_archive)
   if (this_is_the_archive && _remdev (file_name))
     return true;
 
+  /* Ensure that no previously backed-up file remains in case we
+   * return early. */
+  assign_string (&after_backup_name, 0);
+
   if (stat (file_name, &file_stat))
     {
       if (errno == ENOENT)