make proto_tree_add_bitmask_value_with_flags() work for tvb==NULL
authorMartin Kaiser <wireshark@kaiser.cx>
Thu, 22 Dec 2016 23:20:56 +0000 (00:20 +0100)
committerMichael Mann <mmann78@netscape.net>
Fri, 23 Dec 2016 12:40:05 +0000 (12:40 +0000)
proto_tree_add_bitmask_value_with_flags() eventually calls
proto_tree_add_XXX() for the main hf and for the field elements.

These functions work for tvb==NULL if the length is also set to 0.
Otherwise, we'll end up in proto_tree_add_pi(), get_hfi_length() and
run into the DISSECTOR_ASSERT() there.

proto_tree_add_bitmask_value...() are meant for cases where the data is
passed directly and not read from a tvb. If tvb==NULL, set our length to
0 instead of using the field length from the main hf.

Change-Id: Ia55b068e9842ba4a1ae8be8692320a8e93ea8631
Reviewed-on: https://code.wireshark.org/review/19394
Reviewed-by: Martin Kaiser <wireshark@kaiser.cx>
Petri-Dish: Martin Kaiser <wireshark@kaiser.cx>
Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
epan/proto.c

index ae260f72f24b41ed04756cc5166f7b92b62e196d..e00f16b5ef5f79ec2f238da8f743aa10cac7c60e 100644 (file)
@@ -9839,7 +9839,9 @@ proto_tree_add_bitmask_value_with_flags(proto_tree *parent_tree, tvbuff_t *tvb,
 
        PROTO_REGISTRAR_GET_NTH(hf_hdr,hf);
        DISSECTOR_ASSERT_FIELD_TYPE_IS_INTEGRAL(hf);
-       len = ftype_length(hf->type);
+       /* the proto_tree_add_uint/_uint64() calls below
+          will fail if tvb==NULL and len!=0 */
+       len = tvb ? ftype_length(hf->type) : 0;
 
        if (parent_tree) {
                if (len <= 4)