diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-01-27 16:16:30 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-01-27 16:44:08 +0200 |
commit | 858318dde7083d91aea6d6171c4c4c18615ffae0 (patch) | |
tree | 2d381f367803df6ee21e2657e69ed3e7c31acb14 | |
parent | 93386dc14483af2bb60a5d073a4566374bbd516c (diff) | |
download | eclat-858318dde7083d91aea6d6171c4c4c18615ffae0.tar.gz eclat-858318dde7083d91aea6d6171c4c4c18615ffae0.tar.bz2 |
sg: accept -1 as argument to --port
* src/sg-cl.opt (--port option): Accept -1
* src/sg.c (str2port): Likewise.
(add_source_cidr): Fix coredump
-rw-r--r-- | src/sg-cl.opt | 2 | ||||
-rw-r--r-- | src/sg.c | 13 |
2 files changed, 8 insertions, 7 deletions
diff --git a/src/sg-cl.opt b/src/sg-cl.opt index d361d00..6b223b2 100644 --- a/src/sg-cl.opt +++ b/src/sg-cl.opt @@ -89,7 +89,7 @@ OPTION(port,P,[<PORT[-PORT]>], [<destination port number or range>]) BEGIN char *p = strchr(optarg, '-'); - if (p) { + if (p && p > optarg) { *p++ = 0; to_port = p; } else @@ -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; } |