]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Prevent getservbyname() being called with a numeric value on Windows.
authorAmos Jeffries <squid3@treenet.co.nz>
Mon, 6 Jul 2009 01:08:37 +0000 (13:08 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Mon, 6 Jul 2009 01:08:37 +0000 (13:08 +1200)
The function getservebyname() returns garbage values when called with
a numeric port "name" for Windows people.

src/cache_cf.cc

index 6f160b9fccda4082bb12e96966c8182466323f98..fe7e215836fd220e488bddc197f19fc0e61d624a 100644 (file)
@@ -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);
     }