]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
libacl: Fix various issues in ASN and random ACL types
authorAmos Jeffries <squid3@treenet.co.nz>
Mon, 14 Jan 2013 11:52:03 +0000 (04:52 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Mon, 14 Jan 2013 11:52:03 +0000 (04:52 -0700)
* replace malloc+memset pattern with calloc in ASN ACL.
  Highlighted by Coverity Scan, issue 434128.

* Log the event where ACL random is configured with no parameters.

* Improve detecton of negative values in random ACL.
  Detected by Coverity Scan, issue 740486.

NOTE: coverity issues which brought these to view require additional
fixes.

src/acl/Asn.cc
src/acl/Random.cc

index daea68e5cfccd0e4debc6f3339fe73d2e2ca64c9..4956bdec11d44c8dfc9285ed53d30f7829fb4924 100644 (file)
@@ -395,8 +395,6 @@ asStateFree(void *data)
 static int
 asnAddNet(char *as_string, int as_number)
 {
-    rtentry_t *e;
-
     struct squid_radix_node *rn;
     CbDataList<int> **Tail = NULL;
     CbDataList<int> *q = NULL;
@@ -430,9 +428,7 @@ asnAddNet(char *as_string, int as_number)
 
     debugs(53, 3, "asnAddNet: called for " << addr << "/" << mask );
 
-    e = (rtentry_t *)xmalloc(sizeof(rtentry_t));
-
-    memset(e, '\0', sizeof(rtentry_t));
+    rtentry_t *e = (rtentry_t *)xcalloc(1, sizeof(rtentry_t));
 
     e->e_addr.addr = addr;
 
index 35353811d76927ae78d4ed5ddde28aa23fc0e301..4c0ce97770b5c1d34d353e0103078648b2b64bcd 100644 (file)
@@ -88,8 +88,10 @@ ACLRandom::parse()
     char bufa[256], bufb[256];
 
     t = strtokFile();
-    if (!t)
+    if (!t) {
+        debugs(28, DBG_PARSE_NOTE(DBG_IMPORTANT), "ACL random missing pattern");
         return;
+    }
 
     debugs(28, 5, "aclParseRandomData: " << t);
 
@@ -99,7 +101,7 @@ ACLRandom::parse()
     if (sscanf(t, "%[0-9]:%[0-9]", bufa, bufb) == 2) {
         int a = xatoi(bufa);
         int b = xatoi(bufb);
-        if (a == 0 || b == 0) {
+        if (a <= 0 || b <= 0) {
             debugs(28, DBG_CRITICAL, "ERROR: ACL random with bad pattern: '" << t << "'");
             return;
         } else
@@ -107,7 +109,7 @@ ACLRandom::parse()
     } else if (sscanf(t, "%[0-9]/%[0-9]", bufa, bufb) == 2) {
         int a = xatoi(bufa);
         int b = xatoi(bufb);
-        if (a == 0 || b == 0) {
+        if (a <= 0 || b <= 0) {
             debugs(28, DBG_CRITICAL, "ERROR: ACL random with bad pattern: '" << t << "'");
             return;
         } else