diff --git a/Modules/getaddrinfo.c b/Modules/getaddrinfo.c index b6fb53c..a61749d 100644 --- a/Modules/getaddrinfo.c +++ b/Modules/getaddrinfo.c @@ -334,12 +334,17 @@ getaddrinfo(const char*hostname, const char*servname, */ if (servname) { if (str_isnumber(servname)) { + u_long servnum; + if (pai->ai_socktype == GAI_ANY) { /* caller accept *GAI_ANY* socktype */ pai->ai_socktype = SOCK_DGRAM; pai->ai_protocol = IPPROTO_UDP; } - port = htons((u_short)atoi(servname)); + servnum = strtoul(servname, NULL, 10); + if (servnum > 65535) + ERR(EAI_SERVICE); + port = htons((u_short)servnum); } else { struct servent *sp; char *proto;