[BusyBox] Bug in tar

Francois-R Boyer boyerf at IRO.UMontreal.CA
Sat Jan 20 02:31:42 UTC 2001


What I can tell is that if you leave it the way it is (with the "signal(SIGCHLD,
child_died);") it often does a segmentation fault.  If you remove that line, it works
(the program terminates) with all the files I've tested, and I've tested also with
corrupted files.  But with corrupted files, no error message is displayed.

If you want to handle correctly signals, have message displayed and terminate process
in the right order, you must:
  Continue decompression even if the pipe is broken, so that the correct "invalid
compressed data..." error is displayed.
  Wait for unzip to terminate before we exit tar, so that the error message is
displayed before the command prompt.

How to do that:

  in gunzip.c/write_buf:
    if (n == (unsigned) (-1)) {
        if(errno == EPIPE) return;    /* add this line, to ignore broken pipe error */

        write_error_msg();
    }

  in tar.c/tar_unzip_init:
    //signal(SIGCHLD, child_died);  /* remove this, if the child dies, the pipe will
break and the correct error will report to 'read' */
    signal(SIGPIPE, SIG_IGN);  /* be sure that an error is reported to 'read' and
'write' when the pipe is broken, instead of using a signal handler to solve the
problem */

  in tar.c/tar_main:
    status = readTarFile(...);
    if (unzipFlag == TRUE)    /* if we have started a child */
    {
        close(tarFd);    /* break the pipe, just to be sure the pipe do not block */
        waitpid(child_pid, NULL, 0); /* wait for the child to terminate */
    }
  Of course we must #include <sys/wait.h> and child_pid must not be local to
tar_unzip_init.

I have made these modifications, and it works fine, with correct error reporting when
the file is corrupted.

    Francois

Erik Andersen wrote:

> On Sat Jan 20, 2001 at 11:19:37AM +1100, Glenn McGrath wrote:
> > Hmm, im not so conviced about not needing signals(that was Eriks idea)
> > anyone else care to comment ?
>
> I suppose I am biased, but I am certain there are still cases where the parent can
> catch a SIGCHLD.   Hmm.  I suppose we could do what GNU tar does -- it uses
>     signal (SIGCHLD, SIG_DFL);
> which is sufficient to do the job at hand I suppose.
>
>  -Erik
>
> --
> Erik B. Andersen   email:  andersen at lineo.com
> --This message was written using 73% post-consumer electrons--






More information about the busybox mailing list