dcavalca / rpms / rpm

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