From: Amos Jeffries Date: Fri, 26 Jun 2009 09:18:55 +0000 (+1200) Subject: Prevent getservbyname() being called with a numeric value on Windows. X-Git-Tag: SQUID_3_1_0_9~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=90e8c7df1ce5a5ab69e4a3856893d52fb9897088;p=thirdparty%2Fsquid.git Prevent getservbyname() being called with a numeric value on Windows. The function getservebyname() returns garbage values when called with a numeric port "name" for Windows people. --- diff --git a/src/cache_cf.cc b/src/cache_cf.cc index f30575d5c5..0510c4e6b1 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -1613,6 +1613,22 @@ dump_peer(StoreEntry * entry, const char *name, peer * p) } } +/** + * utility function to prevent getservbyname() being called with a numeric value + * on Windows at least it returns garage results. + */ +static bool +isUnsignedNumeric(const char *str, size_t len) +{ + if (len < 1) return false; + + for (; len >0 && *str; str++, len--) { + if (! isdigit(*str)) + return false; + } + return true; +} + /** \param proto 'tcp' or 'udp' for protocol \returns Port the named service is supposed to be listening on. @@ -1628,7 +1644,8 @@ GetService(const char *proto) return 0; /* NEVER REACHED */ } /** Returns either the service port number from /etc/services */ - port = getservbyname(token, proto); + if( !isUnsignedNumeric(token, strlen(token)) ) + port = getservbyname(token, proto); if (port != NULL) { return ntohs((u_short)port->s_port); }