Fixed segfault with 'cut -f 1 -d:' and added 'cut -s' suport.
[oweals/busybox.git] / tar.c
diff --git a/tar.c b/tar.c
index 7d440f451c7c51ac426751100e8bc0c3a9976cd5..836d127e7c2c3781704d011d25d1eeb84b8d6941 100644 (file)
--- a/tar.c
+++ b/tar.c
@@ -246,6 +246,9 @@ extern int tar_main(int argc, char **argv)
                                                break;
                                        }
 #endif
+                                       if (strcmp(*argv, "-help")==0) {
+                                               usage(tar_usage);
+                                       }
                                        break;
 
                                default:
@@ -300,11 +303,14 @@ tarExtractRegularFile(TarInfo *header, int extractFlag, int tostdoutFlag)
 
        /* Open the file to be written, if a file is supposed to be written */
        if (extractFlag==TRUE && tostdoutFlag==FALSE) {
-               if ((outFd=open(header->name, O_CREAT|O_TRUNC|O_WRONLY, header->mode & ~S_IFMT)) < 0)
-                       errorMsg(io_error, header->name, strerror(errno)); 
                /* Create the path to the file, just in case it isn't there...
                 * This should not screw up path permissions or anything. */
                createPath(header->name, 0777);
+               if ((outFd=open(header->name, O_CREAT|O_TRUNC|O_WRONLY, 
+                                               header->mode & ~S_IFMT)) < 0) {
+                       errorMsg(io_error, header->name, strerror(errno)); 
+                       return( FALSE);
+               }
        }
 
        /* Write out the file, if we are supposed to be doing that */
@@ -818,12 +824,15 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st
 
        /* WARNING/NOTICE: I break Hard Links */
        if (S_ISLNK(statbuf->st_mode)) {
+               int link_size=0;
                char buffer[BUFSIZ];
                header.typeflag  = SYMTYPE;
-               if ( readlink(fileName, buffer, sizeof(buffer) - 1) < 0) {
+               link_size = readlink(fileName, buffer, sizeof(buffer) - 1);
+               if ( link_size < 0) {
                        errorMsg("Error reading symlink '%s': %s\n", header.name, strerror(errno));
                        return ( FALSE);
                }
+               buffer[link_size] = '\0';
                strncpy(header.linkname, buffer, sizeof(header.linkname)); 
        } else if (S_ISDIR(statbuf->st_mode)) {
                header.typeflag  = DIRTYPE;