aboutsummaryrefslogtreecommitdiff
path: root/gmid.c
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2020-11-06 14:24:25 +0100
committerOmar Polo <op@omarpolo.com>2020-11-06 14:24:25 +0100
commit3c19febb014ddc7d9afa1b517c108da4b3fda5dc (patch)
treeeb81372ab81188fb74d8001be53e852eabc8f8b2 /gmid.c
parente8cac16e03c5b86eebd6e50b267a3f0479bf3a81 (diff)
ensure the requested protocol is “gemini”
…and not something else that happens to be 6-bytes long.
Diffstat (limited to 'gmid.c')
-rw-r--r--gmid.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/gmid.c b/gmid.c
index cda5b72..c8348a0 100644
--- a/gmid.c
+++ b/gmid.c
@@ -141,17 +141,18 @@ url_after_proto(char *url)
char *s;
const char *proto = "gemini";
const char *marker = "://";
+ size_t i;
+ /* a relative URL */
if ((s = strstr(url, marker)) == NULL)
return url;
- /* not a gemini:// URL */
-
- if (s - strlen(proto) < url)
+ if (s - strlen(proto) != url)
return NULL;
- /* TODO: */
- /* if (strcmp(s - strlen(proto), proto)) */
- /* return NULL; */
+
+ for (i = 0; proto[i] != '\0'; ++i)
+ if (url[i] != proto[i])
+ return NULL;
/* a valid gemini:// URL */
return s + strlen(marker);