Don't reply on an argument of -1 as the last argument of tvb_memcpy()
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 3 Apr 2009 16:53:40 +0000 (16:53 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 3 Apr 2009 16:53:40 +0000 (16:53 +0000)
meaning "to the end of the tvbuff"; we'd like to get rid of the "-1
means to the end of the tvbuff" convention, as in many cases the length
comes from a 32-bit length field in the packet, and we want 0xFFFFFFFF
to be treated, even on ILP32 platforms, as meaning "2^32-1 bytes",
probably giving an exception, rather than as "to the end of the packet".

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@27945 f5534014-38df-0310-8fa8-9805f1628bb7

epan/dissectors/packet-ber.c

index d300e8570c7621c3d7e122e704711362d3ff6b30..6153d239be2eeb1f4d611bf287a5556d93bb0b87 100644 (file)
@@ -3081,16 +3081,25 @@ int
 dissect_ber_GeneralString(asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, char *name_string, guint name_len)
 {
        tvbuff_t *out_tvb = NULL;
+       gint tvb_len;
 
        offset = dissect_ber_restricted_string(FALSE, BER_UNI_TAG_GeneralString, actx, tree, tvb, offset, hf_id, (name_string)?&out_tvb:NULL);
 
        if(name_string) {
-               if(out_tvb && tvb_length(out_tvb) >= name_len) {
-                       tvb_memcpy(out_tvb, (guint8*)name_string, 0, name_len-1);
-                       name_string[name_len-1] = '\0';
-               } else if(out_tvb) {
-                       tvb_memcpy(out_tvb, (guint8*)name_string, 0, -1);
-                       name_string[tvb_length(out_tvb)] = '\0';
+               /*
+                * XXX - do we want to just get what's left in the tvbuff
+                * if the full length isn't available in the tvbuff, or
+                * do we want to throw an exception?
+                */
+               if(out_tvb) {
+                       tvb_len = tvb_length(out_tvb);
+                       if(tvb_len >= name_len) {
+                               tvb_memcpy(out_tvb, (guint8*)name_string, 0, name_len-1);
+                               name_string[name_len-1] = '\0';
+                       } else {
+                               tvb_memcpy(out_tvb, (guint8*)name_string, 0, tvb_len);
+                               name_string[tvb_len] = '\0';
+                       }
                }
        }