From: tb Date: Fri, 26 Aug 2022 11:04:13 +0000 (+0000) Subject: Tweaks in load_skiplist() X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=b764f8f64f6625f1e24a31efbdbfc46ae7ec980f;p=openbsd Tweaks in load_skiplist() If there's an issue opening the default skip list file other than its absence (most likely bad permissions), we should not silently ignore that. Also, use err() instead of errx() to display the error. Second, linelen, the return value of getline(), is not currently used. Repurpose it to save the result of strcspn() which calculates the length of the string we're interested in and use that instead of strlen(). ok claudio --- diff --git a/usr.sbin/rpki-client/main.c b/usr.sbin/rpki-client/main.c index 113a20c928a..b1b9276d4e7 100644 --- a/usr.sbin/rpki-client/main.c +++ b/usr.sbin/rpki-client/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.211 2022/08/25 18:12:05 job Exp $ */ +/* $OpenBSD: main.c,v 1.212 2022/08/26 11:04:13 tb Exp $ */ /* * Copyright (c) 2021 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -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);