[PATCH] tar: Fix descriptor leak in writeFileToTarball() function

Maks Mishin maks.mishinfz at gmail.com
Wed Aug 21 17:12:55 UTC 2024


The handle `inputFileField` is created at tar.c:529 by calling function
`open_or_warn` and lost at tar.c:538 without closing.

Found by static analyzer Svace.

Signed-off-by: Maks Mishin <maks.mishinFZ at gmail.com>
---
 archival/tar.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/archival/tar.c b/archival/tar.c
index d6ca6c1e0..e670239b7 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -534,6 +534,9 @@ static int FAST_FUNC writeFileToTarball(struct recursive_state *state,
 
 	/* Add an entry to the tarball */
 	if (writeTarHeader(tbInfo, header_name, fileName, statbuf) == FALSE) {
+		if (inputFileFd >= 0) {
+			close(inputFileFd);
+		}
 		return FALSE; /* make recursive_action() return FALSE */
 	}
 
-- 
2.30.2



More information about the busybox mailing list