On Fri, Aug 26, 2022 at 09:57:19AM +0200, Theo Buehler wrote:
> First, if there's an issue opening the default skip list file other than
> its absence (most likely bad permissions), we should not silently ignore
> it. Also, let's display the error, so use err().
> 
> Second, linelen, the return value of getline() is not currently used.
> Since strcspn() already computes the length of the string we're
> interested in, we can save that and use it instead of calling strlen().

OK claudio@
 
> Index: main.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/rpki-client/main.c,v
> retrieving revision 1.209
> diff -u -p -r1.209 main.c
> --- main.c    4 Aug 2022 13:44:07 -0000       1.209
> +++ main.c    26 Aug 2022 07:51:06 -0000
> @@ -674,16 +674,15 @@ load_skiplist(const char *slf)
>       struct skiplistentry    *sle;
>       FILE                    *fp;
>       char                    *line = NULL;
> -     size_t                   linesize = 0, s;
> -     ssize_t                  linelen;
> +     size_t                   linesize = 0, linelen, s;
>  
>       if ((fp = fopen(slf, "r")) == NULL) {
> -             if (strcmp(slf, DEFAULT_SKIPLIST_FILE) != 0)
> -                     errx(1, "failed to open skiplist %s", slf);
> -             return;
> +             if (errno == ENOENT && strcmp(slf, DEFAULT_SKIPLIST_FILE) == 0)
> +                     return;
> +             err(1, "failed to open %s", slf);
>       }
>  
> -     while ((linelen = getline(&line, &linesize, fp)) != -1) {
> +     while (getline(&line, &linesize, fp) != -1) {
>               /* just eat comment lines or empty lines*/
>               if (line[0] == '#' || line[0] == '\n')
>                       continue;
> @@ -695,9 +694,10 @@ load_skiplist(const char *slf)
>                * Ignore anything after comment sign, whitespaces,
>                * also chop off LF or CR.
>                */
> -             line[strcspn(line, " #\r\n\t")] = 0;
> +             linelen = strcspn(line, " #\r\n\t");
> +             line[linelen] = '\0';
>  
> -             for (s = 0; s < strlen(line); s++)
> +             for (s = 0; s < linelen; s++)
>                       if (!isalnum((unsigned char)line[s]) &&
>                           !ispunct((unsigned char)line[s]))
>                               errx(1, "invalid entry in skiplist: %s", line);
> 

-- 
:wq Claudio

Reply via email to