From: Amos Jeffries Date: Mon, 6 Jul 2009 01:08:37 +0000 (+1200) Subject: Prevent getservbyname() being called with a numeric value on Windows. X-Git-Tag: SQUID_3_0_STABLE17~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cce7a2b1cdf4ec6c99a8fa3f20bcfeaf49e35d60;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 6f160b9fcc..fe7e215836 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -1597,6 +1597,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. @@ -1612,7 +1628,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); }