add function to check server/hostname - gopher-validator - Gopher validator and… | |
git clone git://git.codemadness.org/gopher-validator | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit e4a622665300d0c8c5ce1a4fa6608f6733f3c191 | |
parent 5ca656215b1e77b7fef4dcf37cd6e429146b9426 | |
Author: Hiltjo Posthuma <[email protected]> | |
Date: Sat, 10 Aug 2019 20:27:37 +0200 | |
add function to check server/hostname | |
this check is incomplete, but should cover some cases | |
Diffstat: | |
M gopher-validator.c | 38 +++++++++++++++++++++++++++++… | |
1 file changed, 38 insertions(+), 0 deletions(-) | |
--- | |
diff --git a/gopher-validator.c b/gopher-validator.c | |
@@ -130,6 +130,41 @@ warning(const char *fmt, ...) | |
} | |
int | |
+isvalidserver(const char *s) | |
+{ | |
+ int colons; | |
+ | |
+ /* IPv6 */ | |
+ if (*s == '[') { | |
+ colons = 0; | |
+ s++; | |
+ for (; *s; s++) { | |
+ if (*s == ':') | |
+ colons++; | |
+ else if (*s == ']') | |
+ break; | |
+ else if (isxdigit((unsigned char)*s)) | |
+ ; | |
+ else | |
+ return 0; | |
+ } | |
+ if (colons < 2 || *s != ']') | |
+ return 0; | |
+ } else { | |
+ if (!*s) | |
+ return 0; | |
+ for (; *s; s++) { | |
+ if (!isalpha((unsigned char)*s) && | |
+ !isdigit((unsigned char)*s) && | |
+ *s != '-' && *s != '.') | |
+ return 0; | |
+ } | |
+ } | |
+ | |
+ return 1; | |
+} | |
+ | |
+int | |
edial(const char *host, const char *port) | |
{ | |
struct addrinfo hints, *res, *res0; | |
@@ -312,6 +347,9 @@ checkdir(FILE *fp) | |
} | |
} | |
+ if (!isvalidserver(v.server)) | |
+ error("%zu: invalid server: %s\n", linenr, v.server); | |
+ | |
/* check port, must be numeric and in range, port 0 is allowed: | |
"Appendix: | |
Note: Port corresponds the the TCP Port Number, its value shou… |