Re: rpki-client: small geofeed parsing bug

2022-12-28 Thread Theo Buehler
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 -  1.8
+++ geofeed.c   22 Dec 2022 10:40:06 -
@@ -16,6 +16,7 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -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);



rpki-client: small geofeed parsing bug

2022-12-22 Thread Theo Buehler
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.

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 -  1.8
+++ geofeed.c   22 Dec 2022 10:18:45 -
@@ -198,8 +198,10 @@ geofeed_parse(X509 **x509, const char *f
 
/* zap comments */
delim = memchr(line, '#', linelen);
-   if (delim != NULL)
+   if (delim != NULL) {
*delim = '\0';
+   linelen = delim - line;
+   }
 
/* Split prefix and location info */
delim = memchr(line, ',', linelen);