update code

This commit is contained in:
zhuchunyi 2019-11-06 19:40:06 +08:00
commit 6b7c4505a3
7 changed files with 544 additions and 0 deletions

View File

@ -0,0 +1,25 @@
From 1f2ec801cf4ac954f84c81e7587ce11998f78911 Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@redhat.com>
Date: Tue, 9 Aug 2011 12:02:26 +0200
Subject: [PATCH] libtar - rhbz #729009
---
libtar/Makefile.in | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/libtar/Makefile.in b/libtar/Makefile.in
index 4e7bca4..94bd198 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@ -s
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
LN_S = @LN_S@
MKDIR = @MKDIR@
--
1.7.4.4

View File

@ -0,0 +1,24 @@
--- libtar-1.2.11/lib/libtar.h.deref 2009-12-30 16:37:03.790121122 +0100
+++ libtar-1.2.11/lib/libtar.h 2009-12-30 16:37:35.521246633 +0100
@@ -172,6 +172,7 @@ 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)))
--- libtar-1.2.11/lib/util.c.deref 2003-01-07 02:41:00.000000000 +0100
+++ libtar-1.2.11/lib/util.c 2009-12-30 17:35:51.860121660 +0100
@@ -148,9 +148,7 @@ oct_to_int(char *oct)
{
int i;
- sscanf(oct, "%o", &i);
-
- return i;
+ return sscanf(oct, "%o", &i) == 1 ? i : 0;
}

View File

@ -0,0 +1,34 @@
diff -up libtar-1.2.11/lib/append.c.foo libtar-1.2.11/lib/append.c
--- libtar-1.2.11/lib/append.c.foo 2003-01-07 02:40:59.000000000 +0100
+++ libtar-1.2.11/lib/append.c 2008-04-03 15:08:07.000000000 +0200
@@ -13,6 +13,8 @@
#include <internal.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/param.h>
diff -up libtar-1.2.11/lib/output.c~ libtar-1.2.11/lib/output.c
--- libtar-1.2.11/lib/output.c~ 2008-04-03 15:11:07.000000000 +0200
+++ libtar-1.2.11/lib/output.c 2008-04-03 15:11:07.000000000 +0200
@@ -13,6 +13,7 @@
#include <internal.h>
#include <stdio.h>
+#include <stdlib.h>
#include <pwd.h>
#include <grp.h>
#include <time.h>
diff -up libtar-1.2.11/lib/wrapper.c~ libtar-1.2.11/lib/wrapper.c
--- libtar-1.2.11/lib/wrapper.c~ 2008-04-03 15:11:28.000000000 +0200
+++ libtar-1.2.11/lib/wrapper.c 2008-04-03 15:11:28.000000000 +0200
@@ -13,6 +13,7 @@
#include <internal.h>
#include <stdio.h>
+#include <stdlib.h>
#include <sys/param.h>
#include <dirent.h>
#include <errno.h>

View File

@ -0,0 +1,241 @@
From abd0274e6b2f708e9eaa29414b07b3f542cec694 Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@redhat.com>
Date: Tue, 15 Oct 2013 19:48:41 -0400
Subject: [PATCH 1/3] fix file descriptor leaks reported by cppcheck
Bug: https://bugzilla.redhat.com/785760
---
lib/append.c | 14 +++++++++-----
lib/extract.c | 4 ++++
libtar/libtar.c | 3 +++
3 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/lib/append.c b/lib/append.c
index e8bd89d..ff58532 100644
--- a/lib/append.c
+++ b/lib/append.c
@@ -216,6 +216,7 @@ 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)
@@ -234,25 +235,28 @@ tar_append_regfile(TAR *t, const char *realname)
{
if (j != -1)
errno = EINVAL;
- return -1;
+ goto fail;
}
if (tar_block_write(t, &block) == -1)
- return -1;
+ goto fail;
}
if (i > 0)
{
j = read(filefd, &block, i);
if (j == -1)
- return -1;
+ goto fail;
memset(&(block[i]), 0, T_BLOCKSIZE - i);
if (tar_block_write(t, &block) == -1)
- return -1;
+ goto fail;
}
+ /* success! */
+ rv = 0;
+fail:
close(filefd);
- return 0;
+ return rv;
}
diff --git a/lib/extract.c b/lib/extract.c
index 36357e7..9fc6ad5 100644
--- a/lib/extract.c
+++ b/lib/extract.c
@@ -228,13 +228,17 @@ 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/libtar/libtar.c b/libtar/libtar.c
index 9fa92b2..bb5644c 100644
--- a/libtar/libtar.c
+++ b/libtar/libtar.c
@@ -83,7 +83,10 @@ 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)
--
1.7.1
From 36629a41208375f5105427e98078127551692028 Mon Sep 17 00:00:00 2001
From: Huzaifa Sidhpurwala <huzaifas@fedoraproject.org>
Date: Tue, 15 Oct 2013 20:02:58 -0400
Subject: [PATCH 2/3] fix memleak on tar_open() failure
---
lib/handle.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/lib/handle.c b/lib/handle.c
index 33a262c..002d23c 100644
--- a/lib/handle.c
+++ b/lib/handle.c
@@ -82,6 +82,7 @@ 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;
}
--
1.7.1
From f3c711cf3054ff366a1a3500cdc8c64ecc2d2da6 Mon Sep 17 00:00:00 2001
From: Huzaifa Sidhpurwala <huzaifas@fedoraproject.org>
Date: Tue, 15 Oct 2013 20:05:04 -0400
Subject: [PATCH 3/3] fix memleaks in libtar sample program
---
libtar/libtar.c | 29 ++++++++++++++++++-----------
1 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/libtar/libtar.c b/libtar/libtar.c
index bb5644c..23f8741 100644
--- a/libtar/libtar.c
+++ b/libtar/libtar.c
@@ -253,6 +253,7 @@ 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;
}
@@ -270,12 +271,13 @@ extract(char *tarfile, char *rootdir)
void
-usage()
+usage(void *rootdir)
{
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);
}
@@ -292,6 +294,7 @@ main(int argc, char *argv[])
int c;
int mode = 0;
libtar_list_t *l;
+ int return_code = -2;
progname = basename(argv[0]);
@@ -313,17 +316,17 @@ main(int argc, char *argv[])
break;
case 'c':
if (mode)
- usage();
+ usage(rootdir);
mode = MODE_CREATE;
break;
case 'x':
if (mode)
- usage();
+ usage(rootdir);
mode = MODE_EXTRACT;
break;
case 't':
if (mode)
- usage();
+ usage(rootdir);
mode = MODE_LIST;
break;
#ifdef HAVE_LIBZ
@@ -332,7 +335,7 @@ main(int argc, char *argv[])
break;
#endif /* HAVE_LIBZ */
default:
- usage();
+ usage(rootdir);
}
if (!mode || ((argc - optind) < (mode == MODE_CREATE ? 2 : 1)))
@@ -341,7 +344,7 @@ main(int argc, char *argv[])
printf("argc - optind == %d\tmode == %d\n", argc - optind,
mode);
#endif
- usage();
+ usage(rootdir);
}
#ifdef DEBUG
@@ -351,21 +354,25 @@ main(int argc, char *argv[])
switch (mode)
{
case MODE_EXTRACT:
- return extract(argv[optind], rootdir);
+ return_code = extract(argv[optind], rootdir);
+ break;
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 create(tarfile, rootdir, l);
+ return_code = create(tarfile, rootdir, l);
+ libtar_list_free(l, NULL);
+ break;
case MODE_LIST:
- return list(argv[optind]);
+ return_code = list(argv[optind]);
+ break;
default:
break;
}
- /* NOTREACHED */
- return -2;
+ free(rootdir);
+ return return_code;
}
--
1.7.1

View File

@ -0,0 +1,148 @@
From ba16223652cfaa656d9c0c2d7bc7ab39dbd12467 Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@redhat.com>
Date: Wed, 23 Oct 2013 15:04:22 +0200
Subject: [PATCH 1/3] decode: avoid using a static buffer in th_get_pathname()
A solution suggested by Chris Frey:
https://lists.feep.net:8080/pipermail/libtar/2013-October/000377.html
Note this can break programs that expect sizeof(TAR) to be fixed.
[upstream commit ec613af2e9371d7a3e1f7c7a6822164a4255b4d1]
---
lib/decode.c | 24 +++++++++++++++++-------
lib/handle.c | 1 +
lib/libtar.h | 3 +++
3 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/lib/decode.c b/lib/decode.c
index c16ea2d..edb2185 100644
--- a/lib/decode.c
+++ b/lib/decode.c
@@ -26,20 +26,30 @@
char *
th_get_pathname(TAR *t)
{
- static TLS_THREAD char filename[MAXPATHLEN];
-
if (t->th_buf.gnu_longname)
return t->th_buf.gnu_longname;
- if (t->th_buf.prefix[0] != '\0')
+ /* 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
{
- snprintf(filename, sizeof(filename), "%.155s/%.100s",
+ snprintf(t->th_pathname, MAXPATHLEN, "%.155s/%.100s",
t->th_buf.prefix, t->th_buf.name);
- return filename;
}
- snprintf(filename, sizeof(filename), "%.100s", t->th_buf.name);
- return filename;
+ /* will be deallocated in tar_close() */
+ return t->th_pathname;
}
diff --git a/lib/handle.c b/lib/handle.c
index 002d23c..a19c046 100644
--- a/lib/handle.c
+++ b/lib/handle.c
@@ -122,6 +122,7 @@ tar_close(TAR *t)
libtar_hash_free(t->h, ((t->oflags & O_ACCMODE) == O_RDONLY
? free
: (libtar_freefunc_t)tar_dev_free));
+ free(t->th_pathname);
free(t);
return i;
diff --git a/lib/libtar.h b/lib/libtar.h
index 7fc4d03..08a8e0f 100644
--- a/lib/libtar.h
+++ b/lib/libtar.h
@@ -85,6 +85,9 @@ typedef struct
int options;
struct tar_header th_buf;
libtar_hash_t *h;
+
+ /* introduced in libtar 1.2.21 */
+ char *th_pathname;
}
TAR;
--
1.7.1
From 8ef92e48bba35d60208cc09be2bab74f69273d15 Mon Sep 17 00:00:00 2001
From: Chris Frey <cdfrey@foursquare.net>
Date: Thu, 24 Oct 2013 17:55:12 -0400
Subject: [PATCH 2/3] Check for NULL before freeing th_pathname
Thanks to Harald Koch for pointing out that AIX 4 and 5 still need this.
[upstream commit 495d0c0eabc5648186e7d58ad54b508d14af38f4]
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
lib/handle.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/lib/handle.c b/lib/handle.c
index a19c046..28a7dc2 100644
--- a/lib/handle.c
+++ b/lib/handle.c
@@ -122,7 +122,8 @@ tar_close(TAR *t)
libtar_hash_free(t->h, ((t->oflags & O_ACCMODE) == O_RDONLY
? free
: (libtar_freefunc_t)tar_dev_free));
- free(t->th_pathname);
+ if (t->th_pathname != NULL)
+ free(t->th_pathname);
free(t);
return i;
--
1.7.1
From 71101392dbab09718d38fabd151bb3cf22fc8b80 Mon Sep 17 00:00:00 2001
From: Chris Frey <cdfrey@foursquare.net>
Date: Thu, 24 Oct 2013 17:58:47 -0400
Subject: [PATCH 3/3] Added stdlib.h for malloc() in lib/decode.c
[upstream commit 20aa09bd7775094a2beb0f136c2c7d9e9fd6c7e6]
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
lib/decode.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/lib/decode.c b/lib/decode.c
index edb2185..35312be 100644
--- a/lib/decode.c
+++ b/lib/decode.c
@@ -13,6 +13,7 @@
#include <internal.h>
#include <stdio.h>
+#include <stdlib.h>
#include <sys/param.h>
#include <pwd.h>
#include <grp.h>
--
1.7.1

BIN
libtar-v1.2.20.tar.gz Normal file

Binary file not shown.

72
libtar.spec Normal file
View File

@ -0,0 +1,72 @@
Name: libtar
Version: 1.2.20
Release: 16
Summary: Library for manipulating tar files from within C programs.
License: MIT
URL: http://repo.or.cz/libtar.git
Source: http://repo.or.cz/libtar.git/snapshot/refs/tags/v1.2.20.tar.gz#/libtar-v1.2.20.tar.gz
Patch0: libtar-1.2.11-missing-protos.patch
Patch1: libtar-1.2.11-mem-deref.patch
Patch2: libtar-1.2.20-fix-resource-leaks.patch
Patch3: libtar-1.2.11-bz729009.patch
Patch4: libtar-1.2.20-no-static-buffer.patch
BuildRequires: libtool git gdb
%description
Libtar is a C library for manipulating POSIX tar files. It handles adding
and extracting files to/from a tar archive. Requires gcc, make, and zlib.
%package devel
Summary: Development files for %{name}
Requires: %{name} = %{version}-%{release}
%description devel
Libraries and header files of %{name} are all in the %{name}-devel package.
%package help
Summary: Help manual for %{name}
%description help
The %{name}-help package conatins man manual etc
%prep
%autosetup -n %{name}-v%{version} -p1 -Sgit
# set correct version for .so build
%global ltversion %(echo %{version} | tr '.' ':')
sed -i 's/-rpath $(libdir)/-rpath $(libdir) -version-number %{ltversion}/' \
lib/Makefile.in
autoreconf --force --install
%build
%configure --disable-static
%make_build
%install
%make_install
# Without this we get no debuginfo and stripping
chmod +x $RPM_BUILD_ROOT%{_libdir}/libtar.so.%{version}
rm $RPM_BUILD_ROOT%{_libdir}/*.la
%ldconfig_scriptlets
%files
%doc TODO README ChangeLog*
%license COPYRIGHT
%{_bindir}/%{name}
%{_libdir}/lib*.so.*
%files devel
%{_includedir}/libtar.h
%{_includedir}/libtar_listhash.h
%{_libdir}/lib*.so
%files help
%{_mandir}/man3/*.3*
%changelog
* Fri Oct 18 2019 openEuler Buildteam <buildteam@openeuler.org> - 1.2.20-16
- Package init