Subject: bin/34265: pax truncates archive when appending fails.
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: None <dieter.NetBSD@pandora.be>
List: netbsd-bugs
Date: 08/23/2006 09:40:01
>Number: 34265
>Category: bin
>Synopsis: pax truncates archive when appending fails.
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Aug 23 09:40:01 +0000 2006
>Originator: dieter roelants
>Release: NetBSD 4.99.1 and lower
>Organization:
>Environment:
System: NetBSD simult.amelgem.be 4.99.1 NetBSD 4.99.1 (SIMULT) #12: Sun Aug 20 15:43:48 CEST 2006 dieter@simult.amelgem.be:/build/obj.i386.current/sys/arch/i386/compile/SIMULT i386
Architecture: i386
Machine: i386
>Description:
pax(1) truncates the archive file when something unexpected
happens while appending to it. For example, if one tries
to append zero files, the archive is left empty. There are
probably other error conditions where this happens, I think
the archive should always remain intact.
>How-To-Repeat:
simult:5:/tmp$ mkdir x
simult:5:/tmp$ cp /etc/f* x/
cp: /etc/fonts is a directory (not copied).
simult:5:/tmp$ pax -wv -f f.tar x/
x
x/ftpusers
x/ftpchroot
x/fstab
x/floppytab
pax: ustar vol 1, 5 files, 0 bytes read, 10240 bytes written in 1 secs (10240 bytes/sec)
simult:5:/tmp$ echo | pax -wv -a -f f.tar
pax: Reading archive to position at the end...done.
simult:5:/tmp$ ls -l f.tar
-rw-r--r-- 1 dieter wheel 0 Aug 23 11:19 f.tar
>Fix:
This patch only fixes the example above (append 0 files),
because that's what bit me. I think the same should happen
for all returns in wr_archive (or at least when in append
mode). I also didn't check whether variables need to be
freed but coverity will probably tell you. ;)
Index: ar_subs.c
===================================================================
RCS file: /cvsroot/src/bin/pax/ar_subs.c,v
retrieving revision 1.49
diff -u -r1.49 ar_subs.c
--- ar_subs.c 11 Feb 2006 11:04:57 -0000 1.49
+++ ar_subs.c 23 Aug 2006 09:16:30 -0000
@@ -552,8 +552,11 @@
/*
* start up the file traversal code and format specific write
*/
- if ((ftree_start() < 0) || ((*frmt->st_wr)() < 0))
+ if ((ftree_start() < 0) || ((*frmt->st_wr)() < 0)) {
+ wr_fin();
+ ar_close();
return 1;
+ }
wrf = frmt->wr;
now = time((time_t *)NULL);