aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsfisher <sfisher@f5534014-38df-0310-8fa8-9805f1628bb7>2011-04-12 22:23:03 +0000
committersfisher <sfisher@f5534014-38df-0310-8fa8-9805f1628bb7>2011-04-12 22:23:03 +0000
commit5ad7441f9dcd74084ffee21b7e7e3f26dfec0efd (patch)
tree7c83ba656414dbe73241641bf022760d5a5243bd
parent5022456181cca93a29c8f28e6b56fc334fc84af8 (diff)
Fix Coverity 524: NEGATIVE_RETURNS
Coverity sees that two calls to tvb_length_remaining() with an offset of 0 may return -1 (for an "out of bounds" condition), which would lead to an assignment of -1 to an unsigned variable and then passing it to functions further down that cannot accept negative values. Use tvb_ensure_length_remaining() to throw an exception in a case of out of bounds access (though unlikely with an offset of 0) instead of tvb_length_remaining(), which would return -1. git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@36615 f5534014-38df-0310-8fa8-9805f1628bb7
-rw-r--r--asn1/snmp/packet-snmp-template.c4
-rw-r--r--epan/dissectors/packet-snmp.c4
2 files changed, 4 insertions, 4 deletions
diff --git a/asn1/snmp/packet-snmp-template.c b/asn1/snmp/packet-snmp-template.c
index 2162905525..216a6c01eb 100644
--- a/asn1/snmp/packet-snmp-template.c
+++ b/asn1/snmp/packet-snmp-template.c
@@ -1174,9 +1174,9 @@ get_user_assoc(tvbuff_t* engine_tvb, tvbuff_t* user_tvb)
if (! ( user_tvb && engine_tvb ) ) return NULL;
- given_username_len = tvb_length_remaining(user_tvb,0);
+ given_username_len = tvb_ensure_length_remaining(user_tvb,0);
given_username = ep_tvb_memdup(user_tvb,0,-1);
- given_engine_len = tvb_length_remaining(engine_tvb,0);
+ given_engine_len = tvb_ensure_length_remaining(engine_tvb,0);
given_engine = ep_tvb_memdup(engine_tvb,0,-1);
for (a = localized_ues; a; a = a->next) {
diff --git a/epan/dissectors/packet-snmp.c b/epan/dissectors/packet-snmp.c
index 5ba70d2d54..89340c0fae 100644
--- a/epan/dissectors/packet-snmp.c
+++ b/epan/dissectors/packet-snmp.c
@@ -1276,9 +1276,9 @@ get_user_assoc(tvbuff_t* engine_tvb, tvbuff_t* user_tvb)
if (! ( user_tvb && engine_tvb ) ) return NULL;
- given_username_len = tvb_length_remaining(user_tvb,0);
+ given_username_len = tvb_ensure_length_remaining(user_tvb,0);
given_username = ep_tvb_memdup(user_tvb,0,-1);
- given_engine_len = tvb_length_remaining(engine_tvb,0);
+ given_engine_len = tvb_ensure_length_remaining(engine_tvb,0);
given_engine = ep_tvb_memdup(engine_tvb,0,-1);
for (a = localized_ues; a; a = a->next) {