summaryrefslogtreecommitdiff
path: root/gps2udp.c
diff options
context:
space:
mode:
authorGary E. Miller <gem@rellim.com>2014-01-03 11:58:18 -0800
committerGary E. Miller <gem@rellim.com>2014-01-03 11:58:18 -0800
commit218516255724f6589f6f991f12e3c7c692f0db02 (patch)
treec89f3d441bc47f6814cdd4bb98593de8aa01c87f /gps2udp.c
parent17d1650f752ebdce066a0e99ef118954a7473970 (diff)
downloadgpsd-218516255724f6589f6f991f12e3c7c692f0db02.tar.gz
lastcha2udp: fix test for valid port number
Found by: Ferry Huberts <mailings@hupie.com> atoi() never returns errno set, yet errno was tested for. strtol() does set errno, and does other checks.
Diffstat (limited to 'gps2udp.c')
-rw-r--r--gps2udp.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/gps2udp.c b/gps2udp.c
index 8549a129..bcc5a743 100644
--- a/gps2udp.c
+++ b/gps2udp.c
@@ -138,6 +138,7 @@ static int open_udp(char **hostport)
{
char *hostname = NULL;
char *portname = NULL;
+ char *endptr = '\0';
int portnum;
struct hostent *hp;
@@ -151,8 +152,9 @@ static int open_udp(char **hostport)
return (-1);
}
- portnum = atoi(portname);
- if (errno != 0) {
+ errno = 0;
+ portnum = strtol(portname, &endptr, 10);
+ if (0 == portnum || '\0' != *endptr || 0 != errno) {
(void)fprintf(stderr, "gps2udp: syntax is [-u hostname:port] [%s] is not a valid port number\n",portname);
return (-1);
}