diff options
author | Gary E. Miller <gem@rellim.com> | 2014-01-03 11:58:18 -0800 |
---|---|---|
committer | Gary E. Miller <gem@rellim.com> | 2014-01-03 11:58:18 -0800 |
commit | 218516255724f6589f6f991f12e3c7c692f0db02 (patch) | |
tree | c89f3d441bc47f6814cdd4bb98593de8aa01c87f /gps2udp.c | |
parent | 17d1650f752ebdce066a0e99ef118954a7473970 (diff) | |
download | gpsd-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.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -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); } |