Skip to contentSkip to conversation

policycoreutils/hll/pp: use argv[optind] appropriately

PATCH In review Stephen Smalley 1 participant 2 messages Jul 16 – Jul 21 SELinux security module

lore
Share & tools
lore

Stephen Smalley

author maintainer
#0 lore raw

PATCH 1/1 policycoreutils/hll/pp: use argv[optind] appropriately

The input and output filenames are read from argv[1] and argv[2] regardless of what getopt consumed so "pp -- foo.pp" tries to open "--". Use optind.

---
 policycoreutils/hll/pp/pp.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
policycoreutils/hll/pp/pp.c +4 -4
index 7280a70b..08d2c56d 100644
@@ -90,8 +90,8 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (argc >= optind + 1 && strcmp(argv[1], "-") != 0) {
-		ifile = argv[1];
+	if (argc >= optind + 1 && strcmp(argv[optind], "-") != 0) {
+		ifile = argv[optind];
 		in = fopen(ifile, "rb");
 		if (in == NULL) {
 			log_err("Failed to open %s: %s", ifile,
@@ -104,8 +104,8 @@ int main(int argc, char **argv)
 		in = stdin;
 	}
 
-	if (argc >= optind + 2 && strcmp(argv[2], "-") != 0) {
-		ofile = argv[2];
+	if (argc >= optind + 2 && strcmp(argv[optind + 1], "-") != 0) {
+		ofile = argv[optind + 1];
 		out = fopen(ofile, "w");
 		if (out == NULL) {
 			log_err("Failed to open %s: %s", ofile,
Signature · 1 line
2.55.0
author maintainer
#1 lore raw
Quoted 6 lines · Stephen Smalley

The input and output filenames are read from argv[1] and argv[2] regardless of what getopt consumed so "pp -- foo.pp" tries to open "--". Use optind.

Merged.

Quoted 33 lines
---
 policycoreutils/hll/pp/pp.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
policycoreutils/hll/pp/pp.c +4 -5
index 7280a70b..08d2c56d 100644
@@ -90,8 +90,8 @@ int main(int argc, char **argv)
                }
        }
 
-       if (argc >= optind + 1 && strcmp(argv[1], "-") != 0) {
-               ifile = argv[1];
+       if (argc >= optind + 1 && strcmp(argv[optind], "-") != 0) {
+               ifile = argv[optind];
                in = fopen(ifile, "rb");
                if (in == NULL) {
                        log_err("Failed to open %s: %s", ifile,
@@ -104,8 +104,8 @@ int main(int argc, char **argv)
                in = stdin;
        }
 
-       if (argc >= optind + 2 && strcmp(argv[2], "-") != 0) {
-               ofile = argv[2];
+       if (argc >= optind + 2 && strcmp(argv[optind + 1], "-") != 0) {
+               ofile = argv[optind + 1];
                out = fopen(ofile, "w");
                if (out == NULL) {
                        log_err("Failed to open %s: %s", ofile,
--

2.55.0