From d6d91fb38b99c875cae56e3c31b4fd938ea2418f Mon Sep 17 00:00:00 2001 From: Packit Service Date: Dec 09 2020 20:34:13 +0000 Subject: Prepare for a new update Reverting patches so we can apply the latest update and changes can be seen in the spec file and sources. --- diff --git a/lib/append.c b/lib/append.c index 6386a50..13e1ace 100644 --- a/lib/append.c +++ b/lib/append.c @@ -13,8 +13,6 @@ #include #include -#include -#include #include #include #include @@ -110,16 +108,9 @@ tar_append_file(TAR *t, const char *realname, const char *savename) td->td_dev = s.st_dev; td->td_h = libtar_hash_new(256, (libtar_hashfunc_t)ino_hash); if (td->td_h == NULL) - { - free(td); return -1; - } if (libtar_hash_add(t->h, td) == -1) - { - libtar_hash_free(td->td_h, free); - free(td); return -1; - } } libtar_hashptr_reset(&hp); if (libtar_hash_getkey(td->td_h, &hp, &(s.st_ino), @@ -223,7 +214,6 @@ tar_append_regfile(TAR *t, const char *realname) int filefd; int i, j; size_t size; - int rv = -1; filefd = open(realname, O_RDONLY); if (filefd == -1) @@ -242,28 +232,25 @@ tar_append_regfile(TAR *t, const char *realname) { if (j != -1) errno = EINVAL; - goto fail; + return -1; } if (tar_block_write(t, &block) == -1) - goto fail; + return -1; } if (i > 0) { j = read(filefd, &block, i); if (j == -1) - goto fail; + return -1; memset(&(block[i]), 0, T_BLOCKSIZE - i); if (tar_block_write(t, &block) == -1) - goto fail; + return -1; } - /* success! */ - rv = 0; -fail: close(filefd); - return rv; + return 0; } diff --git a/lib/decode.c b/lib/decode.c index 35312be..c16ea2d 100644 --- a/lib/decode.c +++ b/lib/decode.c @@ -13,7 +13,6 @@ #include #include -#include #include #include #include @@ -27,30 +26,20 @@ char * th_get_pathname(TAR *t) { + static TLS_THREAD char filename[MAXPATHLEN]; + if (t->th_buf.gnu_longname) return t->th_buf.gnu_longname; - /* allocate the th_pathname buffer if not already */ - if (t->th_pathname == NULL) - { - t->th_pathname = malloc(MAXPATHLEN * sizeof(char)); - if (t->th_pathname == NULL) - /* out of memory */ - return NULL; - } - - if (t->th_buf.prefix[0] == '\0') - { - snprintf(t->th_pathname, MAXPATHLEN, "%.100s", t->th_buf.name); - } - else + if (t->th_buf.prefix[0] != '\0') { - snprintf(t->th_pathname, MAXPATHLEN, "%.155s/%.100s", + snprintf(filename, sizeof(filename), "%.155s/%.100s", t->th_buf.prefix, t->th_buf.name); + return filename; } - /* will be deallocated in tar_close() */ - return t->th_pathname; + snprintf(filename, sizeof(filename), "%.100s", t->th_buf.name); + return filename; } diff --git a/lib/extract.c b/lib/extract.c index 9fc6ad5..36357e7 100644 --- a/lib/extract.c +++ b/lib/extract.c @@ -228,17 +228,13 @@ tar_extract_regfile(TAR *t, char *realname) { if (k != -1) errno = EINVAL; - close(fdout); return -1; } /* write block to output file */ if (write(fdout, buf, ((i > T_BLOCKSIZE) ? T_BLOCKSIZE : i)) == -1) - { - close(fdout); return -1; - } } /* close output file */ diff --git a/lib/handle.c b/lib/handle.c index 28a7dc2..33a262c 100644 --- a/lib/handle.c +++ b/lib/handle.c @@ -82,7 +82,6 @@ tar_open(TAR **t, const char *pathname, tartype_t *type, (*t)->fd = (*((*t)->type->openfunc))(pathname, oflags, mode); if ((*t)->fd == -1) { - libtar_hash_free((*t)->h, NULL); free(*t); return -1; } @@ -122,8 +121,6 @@ tar_close(TAR *t) libtar_hash_free(t->h, ((t->oflags & O_ACCMODE) == O_RDONLY ? free : (libtar_freefunc_t)tar_dev_free)); - if (t->th_pathname != NULL) - free(t->th_pathname); free(t); return i; diff --git a/lib/libtar.h b/lib/libtar.h index 08a8e0f..55f509a 100644 --- a/lib/libtar.h +++ b/lib/libtar.h @@ -85,9 +85,6 @@ typedef struct int options; struct tar_header th_buf; libtar_hash_t *h; - - /* introduced in libtar 1.2.21 */ - char *th_pathname; } TAR; @@ -175,7 +172,6 @@ int th_write(TAR *t); #define TH_ISDIR(t) ((t)->th_buf.typeflag == DIRTYPE \ || S_ISDIR((mode_t)oct_to_int((t)->th_buf.mode)) \ || ((t)->th_buf.typeflag == AREGTYPE \ - && strlen((t)->th_buf.name) \ && ((t)->th_buf.name[strlen((t)->th_buf.name) - 1] == '/'))) #define TH_ISFIFO(t) ((t)->th_buf.typeflag == FIFOTYPE \ || S_ISFIFO((mode_t)oct_to_int((t)->th_buf.mode))) diff --git a/lib/output.c b/lib/output.c index a5262ee..a2db929 100644 --- a/lib/output.c +++ b/lib/output.c @@ -13,7 +13,6 @@ #include #include -#include #include #include #include diff --git a/lib/util.c b/lib/util.c index 11438ef..31e8315 100644 --- a/lib/util.c +++ b/lib/util.c @@ -148,7 +148,9 @@ oct_to_int(char *oct) { int i; - return sscanf(oct, "%o", &i) == 1 ? i : 0; + sscanf(oct, "%o", &i); + + return i; } diff --git a/lib/wrapper.c b/lib/wrapper.c index 2d3f5b9..4cd0652 100644 --- a/lib/wrapper.c +++ b/lib/wrapper.c @@ -13,7 +13,6 @@ #include #include -#include #include #include #include @@ -97,7 +96,6 @@ tar_append_tree(TAR *t, char *realdir, char *savedir) struct dirent *dent; DIR *dp; struct stat s; - int ret = -1; #ifdef DEBUG printf("==> tar_append_tree(0x%lx, \"%s\", \"%s\")\n", @@ -131,26 +129,24 @@ tar_append_tree(TAR *t, char *realdir, char *savedir) dent->d_name); if (lstat(realpath, &s) != 0) - goto fail; + return -1; if (S_ISDIR(s.st_mode)) { if (tar_append_tree(t, realpath, (savedir ? savepath : NULL)) != 0) - goto fail; + return -1; continue; } if (tar_append_file(t, realpath, (savedir ? savepath : NULL)) != 0) - goto fail; + return -1; } - ret = 0; -fail: closedir(dp); - return ret; + return 0; } diff --git a/libtar/Makefile.in b/libtar/Makefile.in index 80bb8d9..7c6f1bc 100644 --- a/libtar/Makefile.in +++ b/libtar/Makefile.in @@ -20,7 +20,7 @@ SHELL = @SHELL@ ### Installation programs and flags INSTALL = @INSTALL@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ -s INSTALL_DATA = @INSTALL_DATA@ LN_S = @LN_S@ MKDIR = @MKDIR@ diff --git a/libtar/libtar.c b/libtar/libtar.c index ac339e7..9fa92b2 100644 --- a/libtar/libtar.c +++ b/libtar/libtar.c @@ -83,16 +83,12 @@ gzopen_frontend(char *pathname, int oflags, int mode) return -1; if ((oflags & O_CREAT) && fchmod(fd, mode)) - { - close(fd); return -1; - } gzf = gzdopen(fd, gzoflags); if (!gzf) { errno = ENOMEM; - close(fd); return -1; } @@ -254,7 +250,6 @@ extract(char *tarfile, char *rootdir) if (tar_extract_all(t, rootdir) != 0) { fprintf(stderr, "tar_extract_all(): %s\n", strerror(errno)); - tar_close(t); return -1; } @@ -272,13 +267,12 @@ extract(char *tarfile, char *rootdir) void -usage(void *rootdir) +usage() { printf("Usage: %s [-C rootdir] [-g] [-z] -x|-t filename.tar\n", progname); printf(" %s [-C rootdir] [-g] [-z] -c filename.tar ...\n", progname); - free(rootdir); exit(-1); } @@ -295,7 +289,6 @@ main(int argc, char *argv[]) int c; int mode = 0; libtar_list_t *l; - int return_code = -2; progname = basename(argv[0]); @@ -317,17 +310,17 @@ main(int argc, char *argv[]) break; case 'c': if (mode) - usage(rootdir); + usage(); mode = MODE_CREATE; break; case 'x': if (mode) - usage(rootdir); + usage(); mode = MODE_EXTRACT; break; case 't': if (mode) - usage(rootdir); + usage(); mode = MODE_LIST; break; #ifdef HAVE_LIBZ @@ -336,7 +329,7 @@ main(int argc, char *argv[]) break; #endif /* HAVE_LIBZ */ default: - usage(rootdir); + usage(); } if (!mode || ((argc - optind) < (mode == MODE_CREATE ? 2 : 1))) @@ -345,7 +338,7 @@ main(int argc, char *argv[]) printf("argc - optind == %d\tmode == %d\n", argc - optind, mode); #endif - usage(rootdir); + usage(); } #ifdef DEBUG @@ -355,25 +348,21 @@ main(int argc, char *argv[]) switch (mode) { case MODE_EXTRACT: - return_code = extract(argv[optind], rootdir); - break; + return extract(argv[optind], rootdir); case MODE_CREATE: tarfile = argv[optind]; l = libtar_list_new(LIST_QUEUE, NULL); for (c = optind + 1; c < argc; c++) libtar_list_add(l, argv[c]); - return_code = create(tarfile, rootdir, l); - libtar_list_free(l, NULL); - break; + return create(tarfile, rootdir, l); case MODE_LIST: - return_code = list(argv[optind]); - break; + return list(argv[optind]); default: break; } - free(rootdir); - return return_code; + /* NOTREACHED */ + return -2; }