diff options
Diffstat (limited to 'src/sg.c')
-rw-r--r-- | src/sg.c | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -99,16 +99,17 @@ add_source_cidr(char *str, int i) if (pe) hints.ai_protocol = pe->p_proto; else { + char *q; errno = 0; - n = strtoul(proto, &p, 0); - if (errno || *p) + n = strtoul(proto, &q, 0); + if (errno || *q) die(EX_USAGE, "%s: unrecognized protocol"); hints.ai_protocol = n; } hints.ai_family = AF_INET; if (getaddrinfo(str, NULL, &hints, &res)) { - p[-1] = '/'; + if (p) p[-1] = '/'; die(EX_USAGE, "invalid network address in %s", str); } @@ -133,7 +134,7 @@ add_source_cidr(char *str, int i) static char * str2port(const char *str, char **pbuf, size_t *psize) { - unsigned long n; + long n; struct servent *p; char *end; @@ -144,12 +145,12 @@ str2port(const char *str, char **pbuf, size_t *psize) } errno = 0; - n = strtoul(str, &end, 10); + n = strtol(str, &end, 10); if (errno) die(EX_USAGE, "%s: invalid port: %s", str, strerror(errno)); if (*end) die(EX_USAGE, "%s: invalid port", str); - if (n > USHRT_MAX) + if (n < -1 || n > USHRT_MAX) die(EX_USAGE, "%s: port number out of range", str); return (char *) str; } |