teknoraver / rpms / rpm

Forked from rpms/rpm 2 months ago
Clone

Blame SOURCES/rpm-4.16.1.3-rpm2archive-error-handling.patch

07acf4
From f1634250587479d664b34b6de1a6546b2c2b9de5 Mon Sep 17 00:00:00 2001
07acf4
From: Florian Festi <ffesti@redhat.com>
07acf4
Date: Mon, 18 Jan 2021 15:02:34 +0100
07acf4
Subject: [PATCH] rpm2archive: Add more error handling
07acf4
07acf4
Cleanly error out if file can't be written instead of segfaulting
07acf4
07acf4
Resolves: #1091
07acf4
---
07acf4
 rpm2archive.c | 17 ++++++++++++-----
07acf4
 1 file changed, 12 insertions(+), 5 deletions(-)
07acf4
07acf4
diff --git a/rpm2archive.c b/rpm2archive.c
07acf4
index 646f1663d..15c5da016 100644
07acf4
--- a/rpm2archive.c
07acf4
+++ b/rpm2archive.c
07acf4
@@ -119,9 +119,14 @@ static int process_package(rpmts ts, char * filename)
07acf4
 
07acf4
     /* create archive */
07acf4
     a = archive_write_new();
07acf4
-    archive_write_add_filter_gzip(a);
07acf4
-    archive_write_set_format_pax_restricted(a);
07acf4
-
07acf4
+    if (archive_write_add_filter_gzip(a) != ARCHIVE_OK) {
07acf4
+	fprintf(stderr, "Error: Could not create gzip output filter\n");
07acf4
+	exit(EXIT_FAILURE);
07acf4
+    }
07acf4
+    if (archive_write_set_format_pax_restricted(a) != ARCHIVE_OK) {
07acf4
+	fprintf(stderr, "Error: Format pax restricted is not supported\n");
07acf4
+	exit(EXIT_FAILURE);
07acf4
+    }
07acf4
     if (!strcmp(filename, "-")) {
07acf4
 	if (isatty(STDOUT_FILENO)) {
07acf4
 	    fprintf(stderr, "Error: refusing to output archive data to a terminal.\n");
07acf4
@@ -130,9 +135,11 @@ static int process_package(rpmts ts, char * filename)
07acf4
 	archive_write_open_fd(a, STDOUT_FILENO);
07acf4
     } else {
07acf4
 	char * outname = rstrscat(NULL, filename, ".tgz", NULL);
07acf4
-	archive_write_open_filename(a, outname);
07acf4
+	if (archive_write_open_filename(a, outname) != ARCHIVE_OK) {
07acf4
+	    fprintf(stderr, "Error: Can't open output file: %s\n", outname);
07acf4
+	    exit(EXIT_FAILURE);
07acf4
+	}
07acf4
 	_free(outname);
07acf4
-	// XXX error handling
07acf4
     }
07acf4
 
07acf4
     entry = archive_entry_new();
07acf4
-- 
07acf4
2.38.1
07acf4