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