From: Amos Jeffries Date: Fri, 10 Apr 2009 08:25:46 +0000 (+1200) Subject: Various errors detected by Coverity scan X-Git-Tag: SQUID_3_0_STABLE14~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1ff5a7018b150512a36506d5f60f298078656064;p=thirdparty%2Fsquid.git 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 03c5c51b18..03175a97e6 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 d001c20684..f653bca91c 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 470fa432f9..19b2fae3ce 100644 --- a/snmplib/snmp_error.c +++ b/snmplib/snmp_error.c @@ -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", diff --git a/src/auth/basic/auth_basic.cc b/src/auth/basic/auth_basic.cc index 00d9956233..a3151adbfa 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 dd44362ffe..16fe186a08 100644 --- a/src/htcp.cc +++ b/src/htcp.cc @@ -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);