File 12493.patch of Package squid
---------------------
PatchSet 12493
Date: 2009/06/25 22:57:34
Author: hno
Branch: SQUID_2_7
Tag: (none)
Log:
Author: serassio
MFC: Windows port: Fix getservbyname() usage abuse.
On Windows, when calling getservbyname() with a numeric value,
sometimes the result is unexpected.
This patch add a check for numeric values before calling it.
Members:
src/cache_cf.c:1.480.2.12->1.480.2.13
Index: squid/src/cache_cf.c
===================================================================
RCS file: /cvsroot/squid/squid/src/cache_cf.c,v
retrieving revision 1.480.2.12
retrieving revision 1.480.2.13
diff -u -r1.480.2.12 -r1.480.2.13
--- squid/src/cache_cf.c 27 Jun 2008 21:52:56 -0000 1.480.2.12
+++ squid/src/cache_cf.c 25 Jun 2009 22:57:34 -0000 1.480.2.13
@@ -1,6 +1,6 @@
/*
- * $Id: cache_cf.c,v 1.480.2.12 2008/06/27 21:52:56 hno Exp $
+ * $Id: cache_cf.c,v 1.480.2.13 2009/06/25 22:57:34 hno Exp $
*
* DEBUG: section 3 Configuration File Parsing
* AUTHOR: Harvest Derived
@@ -1684,6 +1684,23 @@
}
}
+/*
+ * utility function to prevent getservbyname() being called with a numeric value
+ * on Windows at least it returns garage results.
+ */
+static int
+isUnsignedNumeric(const char *str, size_t len)
+{
+ if (len < 1)
+ return 0;
+
+ for (; len > 0 && *str; str++, len--) {
+ if (!isdigit(*str))
+ return 0;
+ }
+ return 1;
+}
+
static u_short
GetService(const char *proto)
{
@@ -1693,7 +1710,8 @@
self_destruct();
return -1; /* NEVER REACHED */
}
- port = getservbyname(token, proto);
+ if (!isUnsignedNumeric(token, strlen(token)))
+ port = getservbyname(token, proto);
if (port != NULL) {
return ntohs((u_short) port->s_port);
}