On Thu, Dec 22, 2022 at 11:26:30AM +0100, Theo Buehler wrote:
> If the line contains no location info and a comma in a comment, what
> follows the comma will be interpreted as location info. Actually ignore
> what's in comments by adjusting the line length.

It's probably better to remove any whitespace before the comment marker
as well. That would be this diff.

Not sure if we should remove trailing whitespace unconditionally,
probably not.

Index: geofeed.c
===================================================================
RCS file: /cvs/src/usr.sbin/rpki-client/geofeed.c,v
retrieving revision 1.8
diff -u -p -r1.8 geofeed.c
--- geofeed.c   14 Dec 2022 10:45:34 -0000      1.8
+++ geofeed.c   22 Dec 2022 10:40:06 -0000
@@ -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 *f
                        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);

Reply via email to