dcavalca / rpms / rpm

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