gawk

[old] Sed-like interface to the Gopher protocol
Log | Files | Refs | LICENSE

commit fbbce21c354959755db3a34342679040491bd83a
parent 83fc771d7dc844383b4db3dce8d60fa668200b2b
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date:   Wed, 23 Dec 2020 16:07:49 -0800

Fix gopher-item validation

While consecutive terminators still raise a false positive the test
itself handles all cases.

Diffstat:
Mmain.c | 13+++++--------
1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/main.c b/main.c @@ -44,7 +44,7 @@ #define MY_FILTER_MAX 4 enum address { AR_PATH, AR_HOST, AR_PORT, AR_NULL }; /* NOTE: see reqtoaddr() */ -enum gphitem { GI_INFO, GI_PATH, GI_HOST, GI_PORT, GI_NULL }; +enum gphitem { GI_INFO, GI_PATH, GI_HOST, GI_PORT, GI_PLUS, GI_NULL }; enum status { ERROR = -1, OK, UNWIND }; typedef int (item_command)(int, const char **, int, const char **); @@ -316,15 +316,12 @@ int splitrun(filter **filters, int argc, const char **argv, unsigned int index, char *s, item_command *func) { int i, n; - char *item[6]; + char *item[GI_NULL + 1]; /* NOTE: argsplit ignores multiple terminators. */ - if (argsplit(item, LEN(item), s, "\t\r\n") != 4) - /* NOTE: not foolproof */ - if (item[4] != NULL && strcmp(item[4], "+") != 0) { - warnx("%d: Not a valid gopher item.", index); - return UNWIND; - } + n = argsplit(item, LEN(item), s, "\t\r\n"); + if (n != 4 && (n < 4 || n > 5 || strcmp(item[GI_PLUS], "+") != 0)) + return UNWIND; for (i = 0; filters[i] != NULL; ++i) { n = filters[i](argc, argv, index, (const char **)item);