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

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