ensure the requested protocol is “gemini”

…and not something else that happens to be 6-bytes long.
This commit is contained in:
Omar Polo 2020-11-06 14:24:25 +01:00
parent e8cac16e03
commit 3c19febb01
No known key found for this signature in database
GPG Key ID: 35F98C96A1786F0D
2 changed files with 12 additions and 6 deletions

View File

@ -1,3 +1,8 @@
2020-11-06 Omar Polo <op@omarpolo.com>
* gmid.c (url_after_proto): ensure that the requested protocol is
“gemini” and not something else thats long 6 bytes.
2020-11-06 Omar Polo <op@venera>
* gmid.1: added option to log to a file

13
gmid.c
View File

@ -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);