[BusyBox] Bug in tar
Francois-R Boyer
boyerf at IRO.UMontreal.CA
Sat Jan 20 14:54:40 UTC 2001
The while loop goes where you've put the close(tarFd) in tar_main. That close, and the two added
in tar_unzip_init just before the exit, are not needed as all files are closed on exit (maybe it
should be optional like BB_FEATURE_CLEAN_UP). I'm sending you the diff file (diff from the
version you just sent me).
For testing, I use a tar file that make a segmentation fault with "busybox tar -ztvf" after
everything is finished, but works well with GNU tar. I don't know what's in the file that is a
problem, but I know that the segmentation fault is caused by the SIGCHLD handler (which I still
say that it is not needed, and removing it corrects the segmentation fault). The file is
available as:
http://www.iro.umontreal.ca/~boyerf/sshd.tgz
The other test is the same file with one character changed in it (I used 'vi' and changed a
character). If you want the same file I used, it is available as:
http://www.iro.umontreal.ca/~boyerf/sshd_bad.tgz
I suppose that any modified .tgz file will do the same thing. With GNU tar it gives:
drwxr-xr-x root/root 0 1999-05-10 04:09 etc/
drwxr-xr-x root/root 0 1998-06-04 07:11 etc/ssh/
-rwxr-xr-x root/root 90908 1999-05-11 22:23 etc/ssh/ssh-keygen
tar: Skipping to next file header
gzip: stdin: invalid compressed data--crc error
tar: Child returned status 1
tar: Error exit delayed from previous errors
With busybox tar, only the three file names are shown and the program terminates as if there was
no error. My modified version of busybox tar gives the following errors (after the file names):
tar: invalid compressed data--crc error
tar: invalid compressed data--length error
François
Glenn McGrath wrote:
> How about something like the attached patch, it makes sense to take the
> 3 close(tarFd) statements out of readTarFile and put one close(tarFd)
> after where it was called from.
>
> I got a bit lost with your while loop as to how it would apply to tar.c,
> but i see what you are trying to do i think.
>
> How are you causing tar -z to fail (so i can test it myself) ?
>
> Glenn
-------------- next part --------------
--- tar.c.his Sat Jan 20 08:44:43 2001
+++ tar.c Sat Jan 20 09:49:13 2001
@@ -49,6 +49,7 @@
#include <time.h>
#include <utime.h>
#include <sys/types.h>
+#include <sys/wait.h>
#include <sys/sysmacros.h>
#include <getopt.h>
#include <fnmatch.h>
@@ -154,12 +155,14 @@
exit(EXIT_FAILURE);
}
+int child_pid;
+
extern int tar_unzip_init(int tarFd)
{
- int child_pid;
static int unzip_pipe[2];
/* Cope if child dies... Otherwise we block forever in read()... */
- signal(SIGCHLD, child_died);
+ //signal(SIGCHLD, child_died);
+ signal(SIGPIPE, SIG_IGN);
if (pipe(unzip_pipe)!=0)
error_msg_and_die("pipe error\n");
@@ -172,8 +175,6 @@
close(unzip_pipe[0]);
gunzip_init();
unzip(tarFd, unzip_pipe[1]);
- close(unzip_pipe[1]);
- close(tarFd);
exit(EXIT_SUCCESS);
}
else {
@@ -326,7 +327,14 @@
#endif
status = readTarFile(tarFd, extractFlag, listFlag, tostdoutFlag,
verboseFlag, extractList, excludeList);
- close(tarFd);
+#ifdef BB_FEATURE_TAR_GZIP
+ if (unzipFlag == TRUE)
+ {
+ char buf[4096];
+ while(waitpid(child_pid, NULL, WNOHANG) == 0)
+ read(tarFd,buf,sizeof(buf));
+ }
+#endif
}
if (status == TRUE)
More information about the busybox
mailing list