michal-grzedzicki / rpms / rpm

Forked from rpms/rpm 4 months ago
Clone

Blame SOURCES/rpm-4.14.3-rpm2archive-parse-popt-options.patch

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