Skip to content

Commit 98cae85

Browse files
dmcilvaneyanphel31
authored andcommitted
libtar: Pull misc Fedora patches, fix CVE-2021-33643, CVE-2021-33644, CVE-2021-33645, CVE-2021-33646 (#3686)
* Apply Fedora patches * Apply linter * Use upstream patch
1 parent 4333fb0 commit 98cae85

7 files changed

+560
-11
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
From 560911b694055b0c677431cf85d4d0d5ebd1a3fd Mon Sep 17 00:00:00 2001
2+
From: Huzaifa Sidhpurwala <[email protected]>
3+
Date: Tue, 15 Oct 2013 14:39:05 +0200
4+
Subject: [PATCH] Fix invalid memory de-reference issue
5+
6+
Bug: https://bugzilla.redhat.com/551415
7+
8+
Signed-off-by: Kamil Dudka <[email protected]>
9+
---
10+
lib/libtar.h | 1 +
11+
lib/util.c | 4 +---
12+
2 files changed, 2 insertions(+), 3 deletions(-)
13+
14+
diff --git a/lib/libtar.h b/lib/libtar.h
15+
index 3b46a13..616ca8f 100644
16+
--- a/lib/libtar.h
17+
+++ b/lib/libtar.h
18+
@@ -173,6 +173,7 @@ int th_write(TAR *t);
19+
#define TH_ISDIR(t) ((t)->th_buf.typeflag == DIRTYPE \
20+
|| S_ISDIR((mode_t)oct_to_int((t)->th_buf.mode)) \
21+
|| ((t)->th_buf.typeflag == AREGTYPE \
22+
+ && strlen((t)->th_buf.name) \
23+
&& ((t)->th_buf.name[strlen((t)->th_buf.name) - 1] == '/')))
24+
#define TH_ISFIFO(t) ((t)->th_buf.typeflag == FIFOTYPE \
25+
|| S_ISFIFO((mode_t)oct_to_int((t)->th_buf.mode)))
26+
diff --git a/lib/util.c b/lib/util.c
27+
index 31e8315..11438ef 100644
28+
--- a/lib/util.c
29+
+++ b/lib/util.c
30+
@@ -148,9 +148,7 @@ oct_to_int(char *oct)
31+
{
32+
int i;
33+
34+
- sscanf(oct, "%o", &i);
35+
-
36+
- return i;
37+
+ return sscanf(oct, "%o", &i) == 1 ? i : 0;
38+
}
39+
40+
41+
--
42+
2.11.4.GIT
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
From 3936c7aa74d89e7a91dfbb2c1b7bfcad58a0355d Mon Sep 17 00:00:00 2001
2+
From: shixuantong <[email protected]>
3+
Date: Wed, 6 Apr 2022 17:40:57 +0800
4+
Subject: [PATCH 1/2] Ensure that sz is greater than 0.
5+
6+
---
7+
lib/block.c | 10 ++++++++++
8+
1 file changed, 10 insertions(+)
9+
10+
diff --git a/lib/block.c b/lib/block.c
11+
index 092bc28..f12c4bc 100644
12+
--- a/lib/block.c
13+
+++ b/lib/block.c
14+
@@ -118,6 +118,11 @@ th_read(TAR *t)
15+
if (TH_ISLONGLINK(t))
16+
{
17+
sz = th_get_size(t);
18+
+ if ((int)sz <= 0)
19+
+ {
20+
+ errno = EINVAL;
21+
+ return -1;
22+
+ }
23+
blocks = (sz / T_BLOCKSIZE) + (sz % T_BLOCKSIZE ? 1 : 0);
24+
if (blocks > ((size_t)-1 / T_BLOCKSIZE))
25+
{
26+
@@ -168,6 +173,11 @@ th_read(TAR *t)
27+
if (TH_ISLONGNAME(t))
28+
{
29+
sz = th_get_size(t);
30+
+ if ((int)sz <= 0)
31+
+ {
32+
+ errno = EINVAL;
33+
+ return -1;
34+
+ }
35+
blocks = (sz / T_BLOCKSIZE) + (sz % T_BLOCKSIZE ? 1 : 0);
36+
if (blocks > ((size_t)-1 / T_BLOCKSIZE))
37+
{
38+
--
39+
2.37.1
40+
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
From 3c7b1fd9bb63d74ecd38b71ffc876dca3ac87a8b Mon Sep 17 00:00:00 2001
2+
From: shixuantong <[email protected]>
3+
Date: Sat, 7 May 2022 17:04:46 +0800
4+
Subject: [PATCH 2/2] fix memory leak
5+
6+
---
7+
lib/libtar.h | 1 +
8+
lib/util.c | 9 ++++++++-
9+
lib/wrapper.c | 11 +++++++++++
10+
libtar/libtar.c | 3 +++
11+
4 files changed, 23 insertions(+), 1 deletion(-)
12+
13+
diff --git a/lib/libtar.h b/lib/libtar.h
14+
index 08a8e0f..8b00e93 100644
15+
--- a/lib/libtar.h
16+
+++ b/lib/libtar.h
17+
@@ -285,6 +285,7 @@ int oct_to_int(char *oct);
18+
/* integer to string-octal conversion, no NULL */
19+
void int_to_oct_nonull(int num, char *oct, size_t octlen);
20+
21+
+void free_longlink_longname(struct tar_header th_buf);
22+
23+
/***** wrapper.c **********************************************************/
24+
25+
diff --git a/lib/util.c b/lib/util.c
26+
index 11438ef..8a42e62 100644
27+
--- a/lib/util.c
28+
+++ b/lib/util.c
29+
@@ -15,6 +15,7 @@
30+
#include <stdio.h>
31+
#include <sys/param.h>
32+
#include <errno.h>
33+
+#include <stdlib.h>
34+
35+
#ifdef STDC_HEADERS
36+
# include <string.h>
37+
@@ -160,4 +161,10 @@ int_to_oct_nonull(int num, char *oct, size_t octlen)
38+
oct[octlen - 1] = ' ';
39+
}
40+
41+
-
42+
+void free_longlink_longname(struct tar_header th_buf)
43+
+{
44+
+ if (th_buf.gnu_longname != NULL)
45+
+ free(th_buf.gnu_longname);
46+
+ if (th_buf.gnu_longlink !=NULL)
47+
+ free(th_buf.gnu_longlink);
48+
+}
49+
diff --git a/lib/wrapper.c b/lib/wrapper.c
50+
index 2d3f5b9..9d2f3bf 100644
51+
--- a/lib/wrapper.c
52+
+++ b/lib/wrapper.c
53+
@@ -36,7 +36,10 @@ tar_extract_glob(TAR *t, char *globname, char *prefix)
54+
if (fnmatch(globname, filename, FNM_PATHNAME | FNM_PERIOD))
55+
{
56+
if (TH_ISREG(t) && tar_skip_regfile(t))
57+
+ {
58+
+ free_longlink_longname(t->th_buf);
59+
return -1;
60+
+ }
61+
continue;
62+
}
63+
if (t->options & TAR_VERBOSE)
64+
@@ -46,9 +49,13 @@ tar_extract_glob(TAR *t, char *globname, char *prefix)
65+
else
66+
strlcpy(buf, filename, sizeof(buf));
67+
if (tar_extract_file(t, buf) != 0)
68+
+ {
69+
+ free_longlink_longname(t->th_buf);
70+
return -1;
71+
+ }
72+
}
73+
74+
+ free_longlink_longname(t->th_buf);
75+
return (i == 1 ? 0 : -1);
76+
}
77+
78+
@@ -82,9 +89,13 @@ tar_extract_all(TAR *t, char *prefix)
79+
"\"%s\")\n", buf);
80+
#endif
81+
if (tar_extract_file(t, buf) != 0)
82+
+ {
83+
+ free_longlink_longname(t->th_buf);
84+
return -1;
85+
+ }
86+
}
87+
88+
+ free_longlink_longname(t->th_buf);
89+
return (i == 1 ? 0 : -1);
90+
}
91+
92+
diff --git a/libtar/libtar.c b/libtar/libtar.c
93+
index ac339e7..b992abb 100644
94+
--- a/libtar/libtar.c
95+
+++ b/libtar/libtar.c
96+
@@ -197,6 +197,7 @@ list(char *tarfile)
97+
{
98+
fprintf(stderr, "tar_skip_regfile(): %s\n",
99+
strerror(errno));
100+
+ free_longlink_longname(t->th_buf);
101+
return -1;
102+
}
103+
}
104+
@@ -218,10 +219,12 @@ list(char *tarfile)
105+
106+
if (tar_close(t) != 0)
107+
{
108+
+ free_longlink_longname(t->th_buf);
109+
fprintf(stderr, "tar_close(): %s\n", strerror(errno));
110+
return -1;
111+
}
112+
113+
+ free_longlink_longname(t->th_buf);
114+
return 0;
115+
}
116+
117+
--
118+
2.37.1
119+

0 commit comments

Comments
 (0)