From 6becdc4dea32a3ad118dbdfa070a9d73cee167a8 Mon Sep 17 00:00:00 2001 From: Leonardo Taccari Date: Sat, 18 Aug 2018 15:18:32 +0200 Subject: [PATCH] Ignore possible extra tab delimited fields According RFC 1436: > [...] If there are yet other tab delimited fields, the basic > Gopher client should ignore them. [...] --- sacc.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/sacc.c b/sacc.c index 67c49c1..cf08cee 100644 --- a/sacc.c +++ b/sacc.c @@ -283,11 +283,11 @@ displaytextitem(Item *item) } static char * -pickfield(char **raw, char sep) +pickfield(char **raw, const char *sep) { char *c, *f = *raw; - for (c = *raw; *c && *c != sep; ++c) + for (c = *raw; *c && strchr(sep, *c) == NULL; ++c) ; *c = '\0'; @@ -309,7 +309,7 @@ invaliditem(char *raw) if (c) *raw++ = '\0'; - return (tabs == 3) ? NULL : raw; + return (tabs >= 3) ? NULL : raw; } static void @@ -327,10 +327,12 @@ molditem(Item *item, char **raw) } item->type = *raw[0]++; - item->username = pickfield(raw, '\t'); - item->selector = pickfield(raw, '\t'); - item->host = pickfield(raw, '\t'); - item->port = pickfield(raw, '\r'); + item->username = pickfield(raw, "\t"); + item->selector = pickfield(raw, "\t"); + item->host = pickfield(raw, "\t"); + item->port = pickfield(raw, "\t\r"); + while (*raw[0] != '\0') + ++*raw; if (!*raw[0]) ++*raw; } -- 2.18.0