aboutsummaryrefslogtreecommitdiff
path: root/src/sg.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sg.c')
-rw-r--r--src/sg.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/sg.c b/src/sg.c
index c8e6af1..a1842c3 100644
--- a/src/sg.c
+++ b/src/sg.c
@@ -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;
}

Return to:

Send suggestions and report system problems to the System administrator.