summaryrefslogtreecommitdiff
path: root/usr.sbin/rpki-client
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2022-12-28 12:16:36 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2022-12-28 12:16:36 +0000
commit25cdff2223164e4836f253180b43a23ebd6d2540 (patch)
tree8b55120ae6496dab734adab0af90206ace43dc15 /usr.sbin/rpki-client
parent3c111e0b0580d305a05613f7a36c6393ac3d86d7 (diff)
Properly ignore comments in geofeed files
Do not consider comments and whitespace leading up to a comment as part of the line. ok claudio job
Diffstat (limited to 'usr.sbin/rpki-client')
-rw-r--r--usr.sbin/rpki-client/geofeed.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/usr.sbin/rpki-client/geofeed.c b/usr.sbin/rpki-client/geofeed.c
index ef28b033b04..e989d808d90 100644
--- a/usr.sbin/rpki-client/geofeed.c
+++ b/usr.sbin/rpki-client/geofeed.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: geofeed.c,v 1.8 2022/12/14 10:45:34 job Exp $ */
+/* $OpenBSD: geofeed.c,v 1.9 2022/12/28 12:16:35 tb Exp $ */
/*
* Copyright (c) 2022 Job Snijders <job@fastly.com>
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -16,6 +16,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <ctype.h>
#include <err.h>
#include <stdlib.h>
#include <string.h>
@@ -192,14 +193,19 @@ geofeed_parse(X509 **x509, const char *fn, char *buf, size_t len)
goto out;
}
- /* Skip empty lines or commented lines. */
- if (linelen == 0 || line[0] == '#')
- continue;
-
- /* zap comments */
+ /* Zap comments and whitespace before them. */
delim = memchr(line, '#', linelen);
- if (delim != NULL)
+ if (delim != NULL) {
+ while (delim > line &&
+ isspace((unsigned char)delim[-1]))
+ delim--;
*delim = '\0';
+ linelen = delim - line;
+ }
+
+ /* Skip empty lines. */
+ if (linelen == 0)
+ continue;
/* Split prefix and location info */
delim = memchr(line, ',', linelen);