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

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