Blame SOURCES/libtar-1.2.20-static-analysis.patch

e7cf86
From a4e32c3d29e93866c180b5837f8aee3989dac3e9 Mon Sep 17 00:00:00 2001
e7cf86
From: Kamil Dudka <kdudka@redhat.com>
e7cf86
Date: Tue, 6 Nov 2018 17:24:05 +0100
e7cf86
Subject: [PATCH] libtar: fix programming mistakes detected by static analysis
e7cf86
e7cf86
---
e7cf86
 lib/append.c    |  7 +++++++
e7cf86
 lib/wrapper.c   | 11 +++++++----
e7cf86
 libtar/libtar.c |  1 +
e7cf86
 3 files changed, 15 insertions(+), 4 deletions(-)
e7cf86
e7cf86
diff --git a/lib/append.c b/lib/append.c
e7cf86
index ff58532..6386a50 100644
e7cf86
--- a/lib/append.c
e7cf86
+++ b/lib/append.c
e7cf86
@@ -110,9 +110,16 @@ tar_append_file(TAR *t, const char *realname, const char *savename)
e7cf86
 		td->td_dev = s.st_dev;
e7cf86
 		td->td_h = libtar_hash_new(256, (libtar_hashfunc_t)ino_hash);
e7cf86
 		if (td->td_h == NULL)
e7cf86
+		{
e7cf86
+			free(td);
e7cf86
 			return -1;
e7cf86
+		}
e7cf86
 		if (libtar_hash_add(t->h, td) == -1)
e7cf86
+		{
e7cf86
+			libtar_hash_free(td->td_h, free);
e7cf86
+			free(td);
e7cf86
 			return -1;
e7cf86
+		}
e7cf86
 	}
e7cf86
 	libtar_hashptr_reset(&hp;;
e7cf86
 	if (libtar_hash_getkey(td->td_h, &hp, &(s.st_ino),
e7cf86
diff --git a/lib/wrapper.c b/lib/wrapper.c
e7cf86
index 44cc435..2d3f5b9 100644
e7cf86
--- a/lib/wrapper.c
e7cf86
+++ b/lib/wrapper.c
e7cf86
@@ -97,6 +97,7 @@ tar_append_tree(TAR *t, char *realdir, char *savedir)
e7cf86
 	struct dirent *dent;
e7cf86
 	DIR *dp;
e7cf86
 	struct stat s;
e7cf86
+	int ret = -1;
e7cf86
 
e7cf86
 #ifdef DEBUG
e7cf86
 	printf("==> tar_append_tree(0x%lx, \"%s\", \"%s\")\n",
e7cf86
@@ -130,24 +131,26 @@ tar_append_tree(TAR *t, char *realdir, char *savedir)
e7cf86
 				 dent->d_name);
e7cf86
 
e7cf86
 		if (lstat(realpath, &s) != 0)
e7cf86
-			return -1;
e7cf86
+			goto fail;
e7cf86
 
e7cf86
 		if (S_ISDIR(s.st_mode))
e7cf86
 		{
e7cf86
 			if (tar_append_tree(t, realpath,
e7cf86
 					    (savedir ? savepath : NULL)) != 0)
e7cf86
-				return -1;
e7cf86
+				goto fail;
e7cf86
 			continue;
e7cf86
 		}
e7cf86
 
e7cf86
 		if (tar_append_file(t, realpath,
e7cf86
 				    (savedir ? savepath : NULL)) != 0)
e7cf86
-			return -1;
e7cf86
+			goto fail;
e7cf86
 	}
e7cf86
 
e7cf86
+	ret = 0;
e7cf86
+fail:
e7cf86
 	closedir(dp);
e7cf86
 
e7cf86
-	return 0;
e7cf86
+	return ret;
e7cf86
 }
e7cf86
 
e7cf86
 
e7cf86
diff --git a/libtar/libtar.c b/libtar/libtar.c
e7cf86
index 23f8741..ac339e7 100644
e7cf86
--- a/libtar/libtar.c
e7cf86
+++ b/libtar/libtar.c
e7cf86
@@ -92,6 +92,7 @@ gzopen_frontend(char *pathname, int oflags, int mode)
e7cf86
 	if (!gzf)
e7cf86
 	{
e7cf86
 		errno = ENOMEM;
e7cf86
+		close(fd);
e7cf86
 		return -1;
e7cf86
 	}
e7cf86
 
e7cf86
-- 
e7cf86
2.17.2
e7cf86