[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-tar] tar append/open problem & code fix

From: SJ
Subject: [Bug-tar] tar append/open problem & code fix
Date: Thu, 23 Feb 2012 15:31:31 -0700
User-agent: Mozilla/5.0 (Windows NT 6.1; rv:10.0.1) Gecko/20120208 Thunderbird/10.0.1

Say one has a tar file called test.tar and wants to append some newfile

This works
tar rvf test.tar newfile

But what if one accidentally types (note the extra '/' in front of the tar file name) and they don't have '/' permissions?
tar rvf /test.tar newfile

What gets incorrectly reported is:
tar: /test.tar: Cannot read: Bad file descriptor
tar: At beginning of tape, quitting now
tar: Error is not recoverable: exiting now

I tracked down the source of the problem in the 1.26 code and made a fix to my local version to verify the correct results
tar: /test.tar: Cannot open: Permission denied
tar: Error is not recoverable: exiting now

The problem is in buffer.c line 753 after the call to rmtopen.

The switch statement on that line is called despite the archive file descriptor being negative.
This is incorrect as no archive was opened and now the errno will get changed by other calls.

L753 switch( check_compressed_archive (NULL) )

The simple fix is to add an 'if' statement prior to the switch as so:

            archive = rmtopen( archive_name_array[0],
                               O_RDWR | O_CREAT | O_BINARY,
                               MODE_RW, rsh_command_option );

            if( archive > 0)

               switch( check_compressed_archive( NULL ) )
                  case ct_none:
                  case ct_tar:

                     FATAL_ERROR ((0, 0,
                                   _("Cannot update compressed archives")));


Now the code falls thru to intended archive file descriptor check.

Hope that helps.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]