richardphibel / rpms / rpm

Forked from rpms/rpm 2 years ago
Clone
eebfa8
From 8f416b275a365426b07c75adfc017e0b18a85450 Mon Sep 17 00:00:00 2001
eebfa8
From: Florian Festi <ffesti@redhat.com>
eebfa8
Date: Fri, 16 Dec 2022 15:45:20 +0100
eebfa8
Subject: [PATCH] rpm2archive: Properly parse popt options
eebfa8
eebfa8
and issue an error message for unknown options. Before unknown options
eebfa8
could mess up the argument parsing leading to reading and writing from
eebfa8
stdin/stdout.
eebfa8
eebfa8
Thanks to Eva Mrakova and the Red Hat QE team for spotting this!
eebfa8
---
eebfa8
 rpm2archive.c | 8 ++++++++
eebfa8
 1 file changed, 8 insertions(+)
eebfa8
eebfa8
diff --git a/rpm2archive.c b/rpm2archive.c
eebfa8
index de1a17d2b..09da8d16b 100644
eebfa8
--- a/rpm2archive.c
eebfa8
+++ b/rpm2archive.c
eebfa8
@@ -233,6 +233,14 @@ int main(int argc, const char *argv[])
eebfa8
 
eebfa8
     optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
eebfa8
     poptSetOtherOptionHelp(optCon, "[OPTIONS]* <FILES>");
eebfa8
+    while ((rc = poptGetNextOpt(optCon)) != -1) {
eebfa8
+	if (rc < 0) {
eebfa8
+	    fprintf(stderr, "%s: %s\n",
eebfa8
+		    poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
eebfa8
+		    poptStrerror(rc));
eebfa8
+	    exit(EXIT_FAILURE);
eebfa8
+	}
eebfa8
+    }
eebfa8
     if (argc < 2 || poptGetNextOpt(optCon) == 0) {
eebfa8
 	poptPrintUsage(optCon, stderr, 0);
eebfa8
 	exit(EXIT_FAILURE);
eebfa8
-- 
eebfa8
2.38.1
eebfa8