]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Various errors detected by Coverity scan
authorAmos Jeffries <squid3@treenet.co.nz>
Fri, 10 Apr 2009 08:25:46 +0000 (20:25 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Fri, 10 Apr 2009 08:25:46 +0000 (20:25 +1200)
 - SNMP error labels enum and name struct size mis-matched
 - several Null-ptr dereferences
 - various unused code

include/snmp_error.h
lib/rfc2617.c
snmplib/snmp_error.c
src/auth/basic/auth_basic.cc
src/htcp.cc

index 03c5c51b18039b27df2c26c735510d27664ae9c6..03175a97e6dd0463f5018edff4822bb386b945c1 100644 (file)
@@ -44,6 +44,7 @@
 #define SNMP_ERR_WRONGTYPE           (0x7)
 #define SNMP_ERR_WRONGLENGTH         (0x8)
 #define SNMP_ERR_WRONGENCODING       (0x9)
+/* 0x0A - 0x0F undefined */
 #define SNMP_ERR_WRONGVALUE          (0x10)
 #define SNMP_ERR_NOCREATION          (0x11)
 #define SNMP_ERR_INCONSISTENTVALUE   (0x12)
index d001c20684a44d452ff4237c06883c25e01ffc25..f653bca91c901d0386a89f477776a8b95c832157 100644 (file)
@@ -94,6 +94,11 @@ CvtBin(const HASHHEX Hex, HASH Bin)
        else
            Bin[i / 2] |= n;
     }
+/* FIXME: Coverity detects the below as dead code.
+  Why? :: right here i == 32 
+    which means the first step of the for loop makes i==16
+    and cannot be < HASHLEN (which is also 16)
+*/
     for (i = i / 2; i < HASHLEN; i++) {
        Bin[i] = '\0';
     }
index 470fa432f9ac8067e27973221dceb4994f50ef5f..19b2fae3ce4fd4df420c9d1e41fe8aba3efda488 100644 (file)
@@ -33,8 +33,8 @@
 #include "snmp_error.h"
 
 
-static const char *error_string[19] =
-{
+static const char *error_string[25] = {
+    /* 0x00 - 0x05 */
     "No Error",
     "Response message would have been too large.",
     "There is no such variable name in this MIB.",
@@ -42,11 +42,21 @@ static const char *error_string[19] =
     "This variable is read only",
     "A general failure occured",
 
-  /* SNMPv2 Errors */
+    /* 0x06 - 0x09 */
     "NOACCESS",
     "WRONGTYPE",
     "WRONGLENGTH",
     "WRONGENCODING",
+
+    /* 0x0A - 0x0F */
+    "UNDEFINED",
+    "UNDEFINED",
+    "UNDEFINED",
+    "UNDEFINED",
+    "UNDEFINED",
+    "UNDEFINED",
+
+    /* 0x10 - 0x18 */
     "WRONGVALUE",
     "NOCREATION",
     "INCONSISTENTVALUE",
index 00d9956233ec71ede1d80bd9ceec9622fabcbdd5..a3151adbfafab260e86034f8e6624d43cc8368d5 100644 (file)
@@ -143,9 +143,8 @@ int
 AuthBasicUserRequest::authenticated() const
 {
     BasicUser const *basic_auth = dynamic_cast<BasicUser const *>(user());
-    assert (basic_auth != NULL);
 
-    if (basic_auth->authenticated())
+    if (basic_auth && basic_auth->authenticated())
         return 1;
 
     return 0;
index dd44362ffebd4f023cfbc1c4cd48b13b67bca73d..16fe186a0803c6f3367b26c0f2d0e7d1239e370c 100644 (file)
@@ -902,19 +902,20 @@ htcpTstReply(htcpDataHeader * dhdr, StoreEntry * e, htcpSpecifier * spec, struct
         stuff.S.uri = spec->uri;
         stuff.S.version = spec->version;
         stuff.S.req_hdrs = spec->req_hdrs;
-        hdr.putInt(HDR_AGE,
-                   e->timestamp <= squid_curtime ?
-                   squid_curtime - e->timestamp : 0);
+        if(e)
+            hdr.putInt(HDR_AGE, (e->timestamp <= squid_curtime ? (squid_curtime - e->timestamp) : 0) );
+        else
+            hdr.putInt(HDR_AGE, 0);
         hdr.packInto(&p);
         stuff.D.resp_hdrs = xstrdup(mb.buf);
         debugs(31, 3, "htcpTstReply: resp_hdrs = {" << stuff.D.resp_hdrs << "}");
         mb.reset();
         hdr.reset();
 
-        if (e->expires > -1)
+        if (e && e->expires > -1)
             hdr.putTime(HDR_EXPIRES, e->expires);
 
-        if (e->lastmod > -1)
+        if (e && e->lastmod > -1)
             hdr.putTime(HDR_LAST_MODIFIED, e->lastmod);
 
         hdr.packInto(&p);