]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
libacl: polish and code fixes
authorAmos Jeffries <squid3@treenet.co.nz>
Sat, 24 Nov 2012 02:12:26 +0000 (19:12 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Sat, 24 Nov 2012 02:12:26 +0000 (19:12 -0700)
* removed several blocks of dead code and useless conditional checks

* Improved handling of garbage config definitions for ACL random, max_conn

* Initialized several uninitialized class members in ACL base class.

 Detected by Coverity Scan.
 Issues 740528, 740343, 740529, 740362, 434117, 740593, 740407.
 Possibly also resolves issue 740486.

src/acl/Acl.cc
src/acl/Asn.cc
src/acl/Checklist.cc
src/acl/DestinationIp.cc
src/acl/Ip.cc
src/acl/MaxConnection.cc
src/acl/Random.cc
src/acl/Random.h

index 11245fc0ec6969d299b91e1f0b2f6f493620b142..5043159ef8159df56c50b7616bdaea260db6e9c5 100644 (file)
@@ -80,7 +80,12 @@ ACL::Factory (char const *type)
     return result;
 }
 
-ACL::ACL () :cfgline(NULL) {}
+ACL::ACL() :
+        cfgline(NULL),
+        next(NULL)
+{
+    *name = 0;
+}
 
 bool ACL::valid () const
 {
index f53420b440c0d56c65e22a6c1f8efcccc55784bd..daea68e5cfccd0e4debc6f3339fe73d2e2ca64c9 100644 (file)
@@ -509,8 +509,6 @@ destroyRadixNodeInfo(as_info * e_info)
         data = data->next;
         delete prev;
     }
-
-    delete data;
 }
 
 static int
index ff413eb082ffe88a7112d450861bbb16b1bd1758..9b98028c16fded3c0e7e7ea6637f90c01fcd61cb 100644 (file)
@@ -320,7 +320,8 @@ ACLChecklist::ACLChecklist() :
         async_(false),
         finished_(false),
         allow_(ACCESS_DENIED),
-        state_(NullState::Instance())
+        state_(NullState::Instance()),
+        checking_(false)
 {
 }
 
index ab2967b112187a9c0ab0327c8bb0ebb834fed2c1..721fc0dd32783489fb6b161f3d1cde85534f2d79 100644 (file)
@@ -54,8 +54,7 @@ ACLDestinationIP::match(ACLChecklist *cl)
     // Bypass of browser same-origin access control in intercepted communication
     // To resolve this we will force DIRECT and only to the original client destination.
     // In which case, we also need this ACL to accurately match the destination
-    if (Config.onoff.client_dst_passthru && checklist->request &&
-            (checklist->request->flags.intercepted || checklist->request->flags.spoofClientIp)) {
+    if (Config.onoff.client_dst_passthru && (checklist->request->flags.intercepted || checklist->request->flags.spoofClientIp)) {
         assert(checklist->conn() && checklist->conn()->clientConnection != NULL);
         return ACLIP::match(checklist->conn()->clientConnection->local);
     }
index ad3f8a2622763f6144a492cf55a1a97ee8e5ea80..578fca96281bcfb016511b460cd81fb7688e7298 100644 (file)
@@ -409,15 +409,6 @@ acl_ip_data::FactoryParse(const char *t)
 
         memset(&hints, 0, sizeof(struct addrinfo));
 
-        if ( iptype != AF_UNSPEC ) {
-            hints.ai_flags |= AI_NUMERICHOST;
-        }
-
-#if 0
-        if (Ip::EnableIpv6&IPV6_SPECIAL_V4MAPPING)
-            hints.ai_flags |= AI_V4MAPPED | AI_ALL;
-#endif
-
         int errcode = getaddrinfo(addr1,NULL,&hints,&hp);
         if (hp == NULL) {
             debugs(28, DBG_CRITICAL, "aclIpParseIpData: Bad host/IP: '" << addr1 <<
index 49d97187ac0b66a8fecb0c65bd8b9ae0c2bdf8b0..30c4eb5049d1d0af11ef16d1ffc1d5c8ee5ea2a1 100644 (file)
@@ -85,8 +85,15 @@ ACLMaxConnection::parse()
     limit = (atoi (t));
 
     /* suck out file contents */
-
+    // ignore comments
+    bool ignore = false;
     while ((t = strtokFile())) {
+        ignore |= (*t != '#');
+
+        if (ignore)
+            continue;
+
+        debugs(89, DBG_CRITICAL, "WARNING: max_conn only accepts a single limit value.");
         limit = 0;
     }
 }
index ca2c25ec9904408596cecdb60eb581efc5e39755..35353811d76927ae78d4ed5ddde28aa23fc0e301 100644 (file)
@@ -72,6 +72,12 @@ ACLRandom::empty () const
     return data == 0.0;
 }
 
+bool
+ACLRandom::valid() const
+{
+    return !empty();
+}
+
 /*******************/
 /* aclParseRandomList */
 /*******************/
@@ -82,6 +88,9 @@ ACLRandom::parse()
     char bufa[256], bufb[256];
 
     t = strtokFile();
+    if (!t)
+        return;
+
     debugs(28, 5, "aclParseRandomData: " << t);
 
     // seed random generator ...
@@ -91,23 +100,23 @@ ACLRandom::parse()
         int a = xatoi(bufa);
         int b = xatoi(bufb);
         if (a == 0 || b == 0) {
-            debugs(28, DBG_CRITICAL, "aclParseRandomData: Bad Pattern: '" << t << "'");
-            self_destruct();
+            debugs(28, DBG_CRITICAL, "ERROR: ACL random with bad pattern: '" << t << "'");
+            return;
         } else
             data = a / (double)(a+b);
     } else if (sscanf(t, "%[0-9]/%[0-9]", bufa, bufb) == 2) {
         int a = xatoi(bufa);
         int b = xatoi(bufb);
         if (a == 0 || b == 0) {
-            debugs(28, DBG_CRITICAL, "aclParseRandomData: Bad Pattern: '" << t << "'");
-            self_destruct();
+            debugs(28, DBG_CRITICAL, "ERROR: ACL random with bad pattern: '" << t << "'");
+            return;
         } else
             data = (double) a / (double) b;
     } else if (sscanf(t, "0.%[0-9]", bufa) == 1) {
         data = atof(t);
     } else {
-        debugs(28, DBG_CRITICAL, "aclParseRandomData: Bad Pattern: '" << t << "'");
-        self_destruct();
+        debugs(28, DBG_CRITICAL, "ERROR: ACL random with bad pattern: '" << t << "'");
+        return;
     }
 
     // save the exact input pattern. so we can display it later.
index 7ebf3e9d4b1a20b51cf8cb0f5dbc30c473c2997f..55d5fe10d1eeb3bfda0582bf4feddcdb85dfeb51 100644 (file)
@@ -53,6 +53,7 @@ public:
     virtual int match(ACLChecklist *checklist);
     virtual wordlist *dump() const;
     virtual bool empty () const;
+    virtual bool valid() const;
 
 protected:
     static Prototype RegistryProtoype;