dcavalca / rpms / rpm

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