summaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-support/libtar/files/0008-decode-avoid-using-a-static-buffer-in-th_get_pathnam.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta-oe/recipes-support/libtar/files/0008-decode-avoid-using-a-static-buffer-in-th_get_pathnam.patch')
-rw-r--r--meta-oe/recipes-support/libtar/files/0008-decode-avoid-using-a-static-buffer-in-th_get_pathnam.patch89
1 files changed, 89 insertions, 0 deletions
diff --git a/meta-oe/recipes-support/libtar/files/0008-decode-avoid-using-a-static-buffer-in-th_get_pathnam.patch b/meta-oe/recipes-support/libtar/files/0008-decode-avoid-using-a-static-buffer-in-th_get_pathnam.patch
new file mode 100644
index 0000000000..beba45405e
--- /dev/null
+++ b/meta-oe/recipes-support/libtar/files/0008-decode-avoid-using-a-static-buffer-in-th_get_pathnam.patch
@@ -0,0 +1,89 @@
1From edbee9832475347183a841a8fd5be71f74e10392 Mon Sep 17 00:00:00 2001
2From: Kamil Dudka <kdudka@redhat.com>
3Date: Wed, 23 Oct 2013 15:04:22 +0200
4Subject: [PATCH] decode: avoid using a static buffer in th_get_pathname()
5
6A solution suggested by Chris Frey:
7https://lists.feep.net:8080/pipermail/libtar/2013-October/000377.html
8
9Note this can break programs that expect sizeof(TAR) to be fixed.
10
11Authored by Kamil Dudka <kdudka@redhat.com>.
12
13Upstream-Status: Backport [https://repo.or.cz/libtar.git/commit/ec613af2e9371d7a3e1f7c7a6822164a4255b4d1]
14
15Signed-off-by: Katariina Lounento <katariina.lounento@vaisala.com>
16---
17 lib/decode.c | 24 +++++++++++++++++-------
18 lib/handle.c | 1 +
19 lib/libtar.h | 3 +++
20 3 files changed, 21 insertions(+), 7 deletions(-)
21
22diff --git a/lib/decode.c b/lib/decode.c
23index c16ea2d..edb2185 100644
24--- a/lib/decode.c
25+++ b/lib/decode.c
26@@ -26,20 +26,30 @@
27 char *
28 th_get_pathname(TAR *t)
29 {
30- static TLS_THREAD char filename[MAXPATHLEN];
31-
32 if (t->th_buf.gnu_longname)
33 return t->th_buf.gnu_longname;
34
35- if (t->th_buf.prefix[0] != '\0')
36+ /* allocate the th_pathname buffer if not already */
37+ if (t->th_pathname == NULL)
38+ {
39+ t->th_pathname = malloc(MAXPATHLEN * sizeof(char));
40+ if (t->th_pathname == NULL)
41+ /* out of memory */
42+ return NULL;
43+ }
44+
45+ if (t->th_buf.prefix[0] == '\0')
46+ {
47+ snprintf(t->th_pathname, MAXPATHLEN, "%.100s", t->th_buf.name);
48+ }
49+ else
50 {
51- snprintf(filename, sizeof(filename), "%.155s/%.100s",
52+ snprintf(t->th_pathname, MAXPATHLEN, "%.155s/%.100s",
53 t->th_buf.prefix, t->th_buf.name);
54- return filename;
55 }
56
57- snprintf(filename, sizeof(filename), "%.100s", t->th_buf.name);
58- return filename;
59+ /* will be deallocated in tar_close() */
60+ return t->th_pathname;
61 }
62
63
64diff --git a/lib/handle.c b/lib/handle.c
65index 002d23c..a19c046 100644
66--- a/lib/handle.c
67+++ b/lib/handle.c
68@@ -122,6 +122,7 @@ tar_close(TAR *t)
69 libtar_hash_free(t->h, ((t->oflags & O_ACCMODE) == O_RDONLY
70 ? free
71 : (libtar_freefunc_t)tar_dev_free));
72+ free(t->th_pathname);
73 free(t);
74
75 return i;
76diff --git a/lib/libtar.h b/lib/libtar.h
77index 7fc4d03..08a8e0f 100644
78--- a/lib/libtar.h
79+++ b/lib/libtar.h
80@@ -85,6 +85,9 @@ typedef struct
81 int options;
82 struct tar_header th_buf;
83 libtar_hash_t *h;
84+
85+ /* introduced in libtar 1.2.21 */
86+ char *th_pathname;
87 }
88 TAR;
89