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

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