summaryrefslogtreecommitdiffstats
path: root/meta-oem-extra-libs/recipes-core/libtar/files/no_static_buffers.patch
blob: 548d7518505fe87e5d659fe14e5cd68ef20c0e4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
From: Kamil Dudka <kdudka@redhat.com>
Date: Wed, 23 Oct 2013 13:04:22 +0000 (+0200)
Origin: http://repo.or.cz/w/libtar.git/commitdiff/ec613af2e9371d7a3e1f7c7a6822164a4255b4d1
Subject: decode: avoid using a static buffer in th_get_pathname()

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.

--- 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>
@@ -26,20 +27,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;
 }
 
 
--- a/lib/handle.c
+++ b/lib/handle.c
@@ -121,6 +121,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;
--- 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;