From f973f7936dd37ca270e35aebf4aeba9bde271e93 Mon Sep 17 00:00:00 2001 From: shixuantong <1726671442@qq.com> Date: Mon, 25 Apr 2022 16:08:14 +0800 Subject: [PATCH] fix memory leaks --- libtar.spec | 6 +- openEuler-fix-memory-leaks.patch | 120 +++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 openEuler-fix-memory-leaks.patch diff --git a/libtar.spec b/libtar.spec index e48bc78..1cb286c 100644 --- a/libtar.spec +++ b/libtar.spec @@ -1,6 +1,6 @@ Name: libtar Version: 1.2.20 -Release: 21 +Release: 22 Summary: Library for manipulating tar files from within C programs. License: BSD URL: http://repo.or.cz/libtar.git @@ -13,6 +13,7 @@ Patch3: libtar-1.2.11-bz729009.patch Patch4: libtar-1.2.20-no-static-buffer.patch Patch5: CVE-2013-4420.patch Patch9000: openEuler-Ensure-that-sz-is-greater-than-0.patch +Patch9001: openEuler-fix-memory-leaks.patch BuildRequires: libtool @@ -71,6 +72,9 @@ rm $RPM_BUILD_ROOT%{_libdir}/*.la %{_mandir}/man3/*.3* %changelog +* Mon Apr 25 2022 shixuantong - 1.2.20-22 +- fix memory leaks + * Wed Apr 06 2022 shixuantong - 1.2.20-21 - Ensure that sz is greater than 0. diff --git a/openEuler-fix-memory-leaks.patch b/openEuler-fix-memory-leaks.patch new file mode 100644 index 0000000..54e1a22 --- /dev/null +++ b/openEuler-fix-memory-leaks.patch @@ -0,0 +1,120 @@ +From 4c831e5d1769bc65689abb3ee48d4db7a04fbde1 Mon Sep 17 00:00:00 2001 +From: shixuantong +Date: Mon, 25 Apr 2022 08:01:35 +0000 +Subject: [PATCH] fix memory leaks + +--- + lib/libtar.h | 2 ++ + lib/util.c | 13 ++++++++++++- + lib/wrapper.c | 11 +++++++++++ + libtar/libtar.c | 3 +++ + 4 files changed, 28 insertions(+), 1 deletion(-) + +diff --git a/lib/libtar.h b/lib/libtar.h +index 08a8e0f..f297d95 100644 +--- a/lib/libtar.h ++++ b/lib/libtar.h +@@ -285,6 +285,8 @@ int oct_to_int(char *oct); + /* integer to string-octal conversion, no NULL */ + void int_to_oct_nonull(int num, char *oct, size_t octlen); + ++/* free the memory*/ ++void libtar_free(struct tar_header th_buf); + + /***** wrapper.c **********************************************************/ + +diff --git a/lib/util.c b/lib/util.c +index 11438ef..57d7292 100644 +--- a/lib/util.c ++++ b/lib/util.c +@@ -15,6 +15,7 @@ + #include + #include + #include ++#include + + #ifdef STDC_HEADERS + # include +@@ -160,4 +161,14 @@ int_to_oct_nonull(int num, char *oct, size_t octlen) + oct[octlen - 1] = ' '; + } + +- ++void libtar_free(struct tar_header th_buf) ++{ ++ if (th_buf.gnu_longname != NULL) ++ { ++ free(th_buf.gnu_longname); ++ } ++ if(th_buf.gnu_longlink != NULL) ++ { ++ free(th_buf.gnu_longlink); ++ } ++} +diff --git a/lib/wrapper.c b/lib/wrapper.c +index 44cc435..9b22567 100644 +--- a/lib/wrapper.c ++++ b/lib/wrapper.c +@@ -36,7 +36,10 @@ tar_extract_glob(TAR *t, char *globname, char *prefix) + if (fnmatch(globname, filename, FNM_PATHNAME | FNM_PERIOD)) + { + if (TH_ISREG(t) && tar_skip_regfile(t)) ++ { ++ libtar_free(t->th_buf); + return -1; ++ } + continue; + } + if (t->options & TAR_VERBOSE) +@@ -46,9 +49,13 @@ tar_extract_glob(TAR *t, char *globname, char *prefix) + else + strlcpy(buf, filename, sizeof(buf)); + if (tar_extract_file(t, buf) != 0) ++ { ++ libtar_free(t->th_buf); + return -1; ++ } + } + ++ libtar_free(t->th_buf); + return (i == 1 ? 0 : -1); + } + +@@ -82,9 +89,13 @@ tar_extract_all(TAR *t, char *prefix) + "\"%s\")\n", buf); + #endif + if (tar_extract_file(t, buf) != 0) ++ { ++ libtar_free(t->th_buf); + return -1; ++ } + } + ++ libtar_free(t->th_buf); + return (i == 1 ? 0 : -1); + } + +diff --git a/libtar/libtar.c b/libtar/libtar.c +index 23f8741..a349640 100644 +--- a/libtar/libtar.c ++++ b/libtar/libtar.c +@@ -196,6 +196,7 @@ list(char *tarfile) + { + fprintf(stderr, "tar_skip_regfile(): %s\n", + strerror(errno)); ++ libtar_free(t->th_buf); + return -1; + } + } +@@ -215,6 +216,8 @@ list(char *tarfile) + ); + #endif + ++ libtar_free(t->th_buf); ++ + if (tar_close(t) != 0) + { + fprintf(stderr, "tar_close(): %s\n", strerror(errno)); +-- +2.33.0 + -- Gitee