commit 3f33776c6162cca7861da1d9e8ee3a27dd0fb1e4
parent ba4e508c95163387fbd16d12243c15469989669c
Author: hhvn <dev@hhvn.uk>
Date: Mon, 17 Jan 2022 13:14:09 +0000
zygo.c: better gopher menu validation (compat with gopher+)
Diffstat:
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/zygo.c b/zygo.c
@@ -281,20 +281,22 @@ gophertoelem(Elem *from, const char *line) {
for (p = tmp, seg = SEGDESC; *p; p++) {
if (*p == '\t') {
- if (seg == SEGPORT)
- goto invalid;
*p = '\0';
switch (seg) {
case SEGDESC: ret->desc = estrdup(tmp); break;
case SEGSELECTOR: ret->selector = estrdup(tmp); break;
case SEGSERVER: ret->server = estrdup(tmp); break;
+ case SEGPORT: ret->port = estrdup(tmp); break;
}
tmp = p + 1;
seg++;
}
}
- ret->port = estrdup(tmp);
+ /* ret->port will only be set on gopher+ menus with
+ * the above loop, set it here for non-gopher+ */
+ if (!ret->port)
+ ret->port = estrdup(tmp);
if (from && from->tls &&
strcmp(ret->server, from->server) == 0 &&
strcmp(ret->port, from->port) == 0)
@@ -303,10 +305,12 @@ gophertoelem(Elem *from, const char *line) {
ret->tls = 0;
free(dup);
- return ret;
-invalid:
- free(dup);
+ if (ret->desc != NULL &&
+ ret->server != NULL &&
+ ret->port != NULL)
+ return ret;
+
free(ret->desc);
free(ret->selector);
free(ret->server);