[Openvpn-devel] Ignore leading whitespace and comment lines for peer-fingerprint.

Message ID 20210518143218.14520-1-gert@greenie.muc.de
State Superseded
Headers show
Series
  • [Openvpn-devel] Ignore leading whitespace and comment lines for peer-fingerprint.
Related show

Commit Message

Gert Doering May 18, 2021, 2:32 p.m.
Inline peer-fingerprint blocks can benefit from a bit of structuring
by indentation or by putting comments ("# this is Alice's key").

Signed-off-by: Gert Doering <gert@greenie.muc.de>
---
 src/openvpn/options.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Selva Nair May 18, 2021, 11:23 p.m. | #1
Hi,

On Tue, May 18, 2021 at 10:33 AM Gert Doering <gert@greenie.muc.de> wrote:
>
> Inline peer-fingerprint blocks can benefit from a bit of structuring
> by indentation or by putting comments ("# this is Alice's key").
>
> Signed-off-by: Gert Doering <gert@greenie.muc.de>
> ---
>  src/openvpn/options.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/src/openvpn/options.c b/src/openvpn/options.c
> index db460796..cfc30193 100644
> --- a/src/openvpn/options.c
> +++ b/src/openvpn/options.c
> @@ -1145,8 +1145,13 @@ parse_hash_fingerprint_multiline(const char *str, int nbytes, int msglevel,
>      const char *line;
>      while ((line = strsep(&lines, "\n")))
>      {
> -        /* skip empty lines */
> -        if (strlen(line) == 0)
> +       /* ignore leading whitespace */
> +       while(isspace(*line))
> +       {
> +           line++;
> +       }
> +        /* skip empty lines and comment lines */
> +        if (strlen(line) == 0 || *line == '#')

As we support two comment characters ('#' and ';'), would be better to
do the same here too. One could relax the requirement of comment as
the first character using parse_line(), but this looks generous
enough.

Selva
Gert Doering May 19, 2021, 5:56 a.m. | #2
Hi,

On Tue, May 18, 2021 at 07:23:44PM -0400, Selva Nair wrote:
> >      while ((line = strsep(&lines, "\n")))
> >      {
> > -        /* skip empty lines */
> > -        if (strlen(line) == 0)
> > +       /* ignore leading whitespace */
> > +       while(isspace(*line))
> > +       {
> > +           line++;
> > +       }
> > +        /* skip empty lines and comment lines */
> > +        if (strlen(line) == 0 || *line == '#')
> 
> As we support two comment characters ('#' and ';'), would be better to
> do the same here too. 

Good point.  v2 is on the way.

> One could relax the requirement of comment as
> the first character using parse_line(), but this looks generous
> enough.

The "ignore leading whitespace" part takes care of this :-) - I looked
at parse_line() but it seemed a bit heavy handed to me.

gert

Patch

diff --git a/src/openvpn/options.c b/src/openvpn/options.c
index db460796..cfc30193 100644
--- a/src/openvpn/options.c
+++ b/src/openvpn/options.c
@@ -1145,8 +1145,13 @@  parse_hash_fingerprint_multiline(const char *str, int nbytes, int msglevel,
     const char *line;
     while ((line = strsep(&lines, "\n")))
     {
-        /* skip empty lines */
-        if (strlen(line) == 0)
+	/* ignore leading whitespace */
+	while(isspace(*line))
+	{
+	    line++;
+	}
+        /* skip empty lines and comment lines */
+        if (strlen(line) == 0 || *line == '#')
         {
             continue;
         }