]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Forward port of patches for Bug #1719 and Bug #1695 from 2.6.
authorserassio <>
Sun, 8 Oct 2006 19:10:34 +0000 (19:10 +0000)
committerserassio <>
Sun, 8 Oct 2006 19:10:34 +0000 (19:10 +0000)
Bug #1719: Incorrect error message on invalid cache_peer specifications

aborted with an assertion on the first request instead of rejecting the
configuration as invalid.

Bug #1695: http_port and other directives accept invalid ports

This patch rejects invalid port specifications in http_port and numerous
other directives as invalid.

src/ACLIntRange.cc
src/ACLMaxUserIP.cc
src/Parsing.cc
src/Parsing.h
src/cache_cf.cc

index b69f51692967bbf196ff92ffc8b91507e06bf1e7..60efec9d37a5b2718ec7302d23a24281cd895b2a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: ACLIntRange.cc,v 1.8 2006/08/26 11:38:56 serassio Exp $
+ * $Id: ACLIntRange.cc,v 1.9 2006/10/08 13:10:34 serassio Exp $
  *
  * DEBUG: section 28    Access Control
  * AUTHOR: Robert Collins
@@ -37,6 +37,7 @@
 #include "squid.h"
 #include "ACLIntRange.h"
 #include "wordlist.h"
+#include "Parsing.h"
 
 /* explicit instantiation required for some systems */
 
@@ -46,28 +47,26 @@ template cbdata_type List<Range<int> >
 void
 ACLIntRange::parse()
 {
-    char *t = NULL;
+    char *a;
 
-    while ((t = strtokFile())) {
-        int port = atoi(t);
+    while ((a = strtokFile())) {
+        char *b = strchr(a, '-');
+        unsigned short port1, port2;
 
-        if (port > 0 && port < 65536) {
-            RangeType temp (0,0);
-            temp.start = port;
-            t = strchr(t, '-');
+        if (b)
+            *b++ = '\0';
 
-            if (t && *(++t)) {
-                port = atoi(t);
+        port1 = xatos(a);
 
-                if (port > 0 && port < 65536 && port > temp.start) {
-                    temp.end = port+1;
-                } else {
-                    debug(28, 0) ("ACLIntRange::parse: Invalid port range\n");
-                    self_destruct();
-                }
-            } else
-                temp.end = temp.start+1;
+        if (b)
+            port2 = xatos(b);
+        else
+            port2 = port1;
 
+        if (port2 >= port1) {
+            RangeType temp (0,0);
+            temp.start = port1;
+            temp.end = port2+1;
             ranges.push_back(temp);
         } else {
             debug(28, 0) ("ACLIntRange::parse: Invalid port value\n");
index 4269219d7eccbde598f548ac4aa5fb8dac0a8ba2..e02c1a97293b663875e3bd19f60995feac21c8b0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: ACLMaxUserIP.cc,v 1.10 2006/04/23 11:10:31 robertc Exp $
+ * $Id: ACLMaxUserIP.cc,v 1.11 2006/10/08 13:10:34 serassio Exp $
  *
  * DEBUG: section 28    Access Control
  * AUTHOR: Duane Wessels
@@ -102,7 +102,7 @@ ACLMaxUserIP::parse()
     if (!t)
         return;
 
-    maximum = atoi(t);
+    maximum = xatoi(t);
 
     debug(28, 5) ("aclParseUserMaxIP: Max IP address's %d\n", (int) maximum);
 
index 1b8c03651205a222404c7be9198f767c1a8ebf15..cb689ba92e59b5004e2512a954d86c3bd53c5169 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: Parsing.cc,v 1.2 2005/11/21 23:06:51 wessels Exp $
+ * $Id: Parsing.cc,v 1.3 2006/10/08 13:10:34 serassio Exp $
  *
  * DEBUG: section 3     Configuration File Parsing
  * AUTHOR: Harvest Derived
  * These functions is the same as atoi/l/f, except that they check for errors
  */
 
-long
-xatol(const char *token)
+double
+xatof(const char *token)
 {
     char *end;
-    long ret = strtol(token, &end, 10);
+    double ret = strtod(token, &end);
 
     if (ret == 0 && end == token)
         self_destruct();
@@ -57,6 +57,29 @@ xatoi(const char *token)
     return xatol(token);
 }
 
+long
+xatol(const char *token)
+{
+    char *end;
+    long ret = strtol(token, &end, 10);
+
+    if (end == token || *end)
+        self_destruct();
+
+    return ret;
+}
+
+unsigned short
+xatos(const char *token)
+{
+    long port = xatol(token);
+
+    if (port & ~0xFFFF)
+        self_destruct();
+
+    return port;
+}
+
 int
 GetInteger(void)
 {
@@ -72,6 +95,17 @@ GetInteger(void)
     return i;
 }
 
+u_short
+GetShort(void)
+{
+    char *token = strtok(NULL, w_space);
+
+    if (token == NULL)
+        self_destruct();
+
+    return xatos(token);
+}
+
 bool
 StringToInt(const char *s, int &result, const char **p, int base)
 {
index 182251e9ace57186c6c5ee4cb3907a01ac8334b7..91613bad54ef26b4a2919308d4c98c18810fabdd 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: Parsing.h,v 1.2 2005/11/21 23:06:51 wessels Exp $
+ * $Id: Parsing.h,v 1.3 2006/10/08 13:10:34 serassio Exp $
  *
  * DEBUG: section 3     Configuration File Parsing
  * AUTHOR: Harvest Derived
 
 #include "squid.h"
 
-extern long xatol(const char *token);
+extern double xatof(const char *token);
 extern int xatoi(const char *token);
+extern long xatol(const char *token);
+extern unsigned short xatos(const char *token);
 extern int GetInteger(void);
+extern u_short GetShort(void);
 
 // on success, returns true and sets *p (if any) to the end of the integer
 extern bool StringToInt(const char *str, int &result, const char **p, int base);
index 699d38a7c12e1342609566ad8155531adb9c5d2a..e137b429e129b530d6e66d5ebc2268a0fc23109b 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: cache_cf.cc,v 1.500 2006/07/02 16:53:46 serassio Exp $
+ * $Id: cache_cf.cc,v 1.501 2006/10/08 13:10:34 serassio Exp $
  *
  * DEBUG: section 3     Configuration File Parsing
  * AUTHOR: Harvest Derived
@@ -162,22 +162,6 @@ self_destruct(void)
     LegacyParser.destruct();
 }
 
-/*
- * These functions is the same as atoi/l/f, except that they check for errors
- */
-
-static double
-xatof(const char *token)
-{
-    char *end;
-    double ret = strtod(token, &end);
-
-    if (ret == 0 && end == token)
-        self_destruct();
-
-    return ret;
-}
-
 static void
 update_maxobjsize(void)
 {
@@ -1495,7 +1479,6 @@ parse_peer(peer ** head)
 {
     char *token = NULL;
     peer *p;
-    int i;
     CBDATA_INIT_TYPE_FREECB(peer, peerDestroy);
     p = cbdataAlloc(peer);
     p->http_port = CACHE_HTTP_PORT;
@@ -1516,13 +1499,12 @@ parse_peer(peer ** head)
 
     p->type = parseNeighborType(token);
 
-    i = GetInteger();
-
-    p->http_port = (u_short) i;
+    p->http_port = GetShort();
 
-    i = GetInteger();
+    if (!p->http_port)
+        self_destruct();
 
-    p->icp.port = (u_short) i;
+    p->icp.port = GetShort();
 
     while ((token = strtok(NULL, w_space))) {
         if (!strcasecmp(token, "proxy-only")) {
@@ -1935,20 +1917,14 @@ static void
 parse_ushortlist(ushortlist ** P)
 {
     char *token;
-    int i;
+    u_short i;
     ushortlist *u;
     ushortlist **U;
 
     while ((token = strtok(NULL, w_space))) {
-        if (sscanf(token, "%d", &i) != 1)
-            self_destruct();
-
-        if (i < 0)
-            i = 0;
-
+        i = GetShort();
         u = xcalloc(1, sizeof(ushortlist));
-
-        u->i = (u_short) i;
+        u->i = i;
 
         for (U = P; *U; U = &(*U)->next)
 
@@ -2435,14 +2411,7 @@ parse_ushort(u_short * var)
 void
 ConfigParser::ParseUShort(u_short *var)
 {
-    int i;
-
-    i = GetInteger();
-
-    if (i < 0)
-        i = 0;
-
-    *var = (u_short) i;
+    *var = GetShort();
 }
 
 void
@@ -2626,7 +2595,7 @@ parse_sockaddr_in_list_token(sockaddr_in_list ** head, char *token)
         /* host:port */
         host = token;
         *t = '\0';
-        port = (unsigned short) xatoi(t + 1);
+        port = xatos(t + 1);
 
         if (0 == port)
             self_destruct();
@@ -2715,16 +2684,15 @@ parse_http_port_specification(http_port_list * s, char *token)
         /* host:port */
         host = token;
         *t = '\0';
-        port = (unsigned short) atoi(t + 1);
-
-        if (0 == port)
-            self_destruct();
-    } else if ((port = atoi(token)) > 0) {
-        /* port */
+        port = xatos(t + 1);
     } else {
-        self_destruct();
+        /* port */
+        port = xatos(token);
     }
 
+    if (port == 0)
+        self_destruct();
+
     s->s.sin_port = htons(port);
 
     if (NULL == host)
@@ -2758,7 +2726,7 @@ parse_http_port_option(http_port_list * s, char *token)
         s->vport = -1;
         s->accel = 1;
     } else if (strncmp(token, "vport=", 6) == 0) {
-        s->vport = atoi(token + 6);
+        s->vport = xatos(token + 6);
         s->accel = 1;
     } else if (strncmp(token, "protocol=", 9) == 0) {
         s->protocol = xstrdup(token + 9);