Re: [PATCH] policycoreutils/hll/pp: use argv[optind] appropriately
Stephen Smalley <[email protected]> Tue, 21 Jul 2026 08:50:17 -0400
| Newsgroups | org.kernel.vger.selinux |
|---|---|
| Message-ID | <CAEjxPJ6s47_951mtwj=EbjiAWa=6AOizEVm4rvodX8FxigWgZg@mail.gmail.com> |
On Thu, Jul 16, 2026 at 10:42 AM Stephen Smalley <[email protected]> wrote: > > 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. > > Signed-off-by: Stephen Smalley <[email protected]> Merged. > --- > policycoreutils/hll/pp/pp.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/policycoreutils/hll/pp/pp.c b/policycoreutils/hll/pp/pp.c > index 7280a70b..08d2c56d 100644 > --- a/policycoreutils/hll/pp/pp.c > +++ b/policycoreutils/hll/pp/pp.c > @@ -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 >