diff options
author | Hiltjo Posthuma <hiltjo@codemadness.org> | 2016-04-10 19:33:27 +0200 |
---|---|---|
committer | Hiltjo Posthuma <hiltjo@codemadness.org> | 2016-04-10 19:33:27 +0200 |
commit | 969ec64ef3195e00ae597e49a39e804bb6ce6464 (patch) | |
tree | ae5e8b38769d5fef951c64f4bac9bc15f6d3ddeb | |
parent | c16ebc65b86d3cf8e76138414665908c71e22cdd (diff) |
util: standard pattern to check for valid number strtoul
-rw-r--r-- | util.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -77,10 +77,11 @@ parseuri(const char *s, struct uri *u, int rel) return -1; /* port too long */ memcpy(u->port, p, i); u->port[i] = '\0'; - /* check for valid port */ + /* check for valid port: range 1 - 65535 */ errno = 0; l = strtoul(u->port, &endptr, 10); - if (errno || *endptr != '\0' || !l || l > 65535) + if (errno || u->port[0] == '\0' || *endptr || + !l || l > 65535) return -1; p = &p[i]; } |