]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Author: Amos Jeffries <squid3@treenet.co.nz>
authorAmos Jeffries <squid3@treenet.co.nz>
Thu, 9 Apr 2009 12:32:26 +0000 (00:32 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Thu, 9 Apr 2009 12:32:26 +0000 (00:32 +1200)
Various errors detected by Coverity scan

 - 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
src/ip/IpAddress.cc
src/ip/IpAddress.h

index 82a0a3dc3b37556e44d4537e860289d2356512c8..c3478110e888147c286079ba20c06eb80217006b 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 f5c50d40048edfdb4885c0b4924710e6e49a2586..324d48078ef1c9229a9ad685cae26609593adb27 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 3fc747fce374e485e84c88c5036d378be2bc64d7..a68d4dbfa02d1b48f402147f601af5cb824cf1a5 100644 (file)
@@ -33,7 +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.",
@@ -41,11 +42,22 @@ static const char *error_string[19] = {
     "This variable is read only",
     "A general failure occured",
 
+    /* 0x06 - 0x09 */
     /* SNMPv2 Errors */
     "NOACCESS",
     "WRONGTYPE",
     "WRONGLENGTH",
     "WRONGENCODING",
+
+    /* 0x0A - 0x0F */
+    "UNDEFINED",
+    "UNDEFINED",
+    "UNDEFINED",
+    "UNDEFINED",
+    "UNDEFINED",
+    "UNDEFINED",
+
+    /* 0x10 - 0x18 */
     "WRONGVALUE",
     "NOCREATION",
     "INCONSISTENTVALUE",
index 4fdee3b5250110ecfb80ebf2d05df51db18dce1f..9aa07bb53a7126a8902e400123bdb88e8f50c6b6 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 b0bcd2ce49b138cda4347a9d6158730e823aabc2..75173a40d841d4530f2d5b9dfe55d23f15f9864e 100644 (file)
@@ -881,19 +881,20 @@ htcpTstReply(htcpDataHeader * dhdr, StoreEntry * e, htcpSpecifier * spec, IpAddr
         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);
index 2cf158280fe1601d6c223e5752b39e3b8ffa0704..798bf030fb9286019f008b646a5711f6125e4a97 100644 (file)
@@ -646,16 +646,8 @@ IpAddress::IpAddress(const IpAddress &s)
 IpAddress::IpAddress(IpAddress *s)
 {
     SetEmpty();
-    operator=(s);
-}
-
-IpAddress& IpAddress::operator =(IpAddress *s)
-{
-    IpAddress *tmp = NULL;
-    if (!s) return *this;
-    tmp = dynamic_cast<IpAddress*>(s);
-    if (!tmp) return *this;
-    return operator=(*tmp);
+    if (s)
+       memcpy(this, s, sizeof(IpAddress));
 }
 
 IpAddress::IpAddress(const struct hostent &s)
index eb4c482ba4e7e829c6cf8b95ab1207326386f5b9..94507c55811f1cb207303f445092b70c23d812c2 100644 (file)
@@ -133,7 +133,6 @@ public:
     /** @name Assignment Operators */
     /*@{*/
     IpAddress& operator =(const IpAddress &s);
-    IpAddress& operator =(IpAddress *s);
     IpAddress& operator =(struct sockaddr_in const &s);
     IpAddress& operator =(struct sockaddr_storage const &s);
     IpAddress& operator =(struct in_addr const &s);