From: Amos Jeffries Date: Thu, 9 Apr 2009 12:32:26 +0000 (+1200) Subject: Author: Amos Jeffries X-Git-Tag: SQUID_3_1_0_8~60 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=48a721c3f44412cfcc79c883a5b8c04416ccf1b5;p=thirdparty%2Fsquid.git Author: Amos Jeffries Various errors detected by Coverity scan - SNMP error labels enum and name struct size mis-matched - several Null-ptr dereferences - various unused code --- diff --git a/include/snmp_error.h b/include/snmp_error.h index 82a0a3dc3b..c3478110e8 100644 --- a/include/snmp_error.h +++ b/include/snmp_error.h @@ -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) diff --git a/lib/rfc2617.c b/lib/rfc2617.c index f5c50d4004..324d48078e 100644 --- a/lib/rfc2617.c +++ b/lib/rfc2617.c @@ -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'; } diff --git a/snmplib/snmp_error.c b/snmplib/snmp_error.c index 3fc747fce3..a68d4dbfa0 100644 --- a/snmplib/snmp_error.c +++ b/snmplib/snmp_error.c @@ -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", diff --git a/src/auth/basic/auth_basic.cc b/src/auth/basic/auth_basic.cc index 4fdee3b525..9aa07bb53a 100644 --- a/src/auth/basic/auth_basic.cc +++ b/src/auth/basic/auth_basic.cc @@ -143,9 +143,8 @@ int AuthBasicUserRequest::authenticated() const { BasicUser const *basic_auth = dynamic_cast(user()); - assert (basic_auth != NULL); - if (basic_auth->authenticated()) + if (basic_auth && basic_auth->authenticated()) return 1; return 0; diff --git a/src/htcp.cc b/src/htcp.cc index b0bcd2ce49..75173a40d8 100644 --- a/src/htcp.cc +++ b/src/htcp.cc @@ -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); diff --git a/src/ip/IpAddress.cc b/src/ip/IpAddress.cc index 2cf158280f..798bf030fb 100644 --- a/src/ip/IpAddress.cc +++ b/src/ip/IpAddress.cc @@ -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(s); - if (!tmp) return *this; - return operator=(*tmp); + if (s) + memcpy(this, s, sizeof(IpAddress)); } IpAddress::IpAddress(const struct hostent &s) diff --git a/src/ip/IpAddress.h b/src/ip/IpAddress.h index eb4c482ba4..94507c5581 100644 --- a/src/ip/IpAddress.h +++ b/src/ip/IpAddress.h @@ -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);