Blame SOURCES/libtar-1.2.20-no-static-buffer.patch

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