From db0ba731ca4f6ee843ad2dd1c70bbae2c6603ae8 Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Thu, 17 Mar 2022 17:11:35 -0500 Subject: [PATCH] asn1: Allow comments and leading ws in opt files --- lib/asn1/asn1_compile.1 | 5 +++++ lib/asn1/main.c | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/asn1/asn1_compile.1 b/lib/asn1/asn1_compile.1 index a7953df5f..9af27672c 100644 --- a/lib/asn1/asn1_compile.1 +++ b/lib/asn1/asn1_compile.1 @@ -330,6 +330,11 @@ to form the names of the files generated. .It Fl Fl option-file=FILE Take additional command-line options from .Ar FILE . +The options file must have one command-line option per-line, but +leading whitespace is ignored, and lines that start with a hash +symbol +.Sq ( # ) +are comments and are ignored. .It Fl Fl original-order Attempt to preserve the original order of type definition in the ASN.1 module. diff --git a/lib/asn1/main.c b/lib/asn1/main.c index bcfdad62e..569b4782b 100644 --- a/lib/asn1/main.c +++ b/lib/asn1/main.c @@ -409,8 +409,16 @@ main(int argc, char **argv) sz = 2; while (fgets(buf, sizeof(buf), opt) != NULL) { + size_t buflen, ws; + buf[strcspn(buf, "\n\r")] = '\0'; + buflen = strlen(buf); + if ((ws = strspn(buf, " \t"))) + memmove(buf, buf + ws, buflen -= ws); + if (buf[0] == '\0' || buf[0] == '#') + continue; + if (len + 1 >= sz) { arg = realloc(arg, (sz + (sz>>1) + 2) * sizeof(arg[0])); if (arg == NULL) {