From dc9f7820176b7c7c85f6ac290a2ca2d0941219e1 Mon Sep 17 00:00:00 2001 From: Michael Mann Date: Sun, 29 Nov 2015 00:13:59 +0000 Subject: [PATCH] Add BASE_ALLOW_ZERO for byte arrays that are validly zero sized. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit implies that the field should be there and isn't. Allow dissectors to specify when a zero-sized array for a field is perfectly valid. Ping-Bug: 11803 Change-Id: I3fd60e3c6f832c6b4a3a8837ebc52c3e74e795ae Reviewed-on: https://code.wireshark.org/review/12271 Petri-Dish: Michael Mann Tested-by: Petri Dish Buildbot Reviewed-by: Alexis La Goutte Reviewed-by: João Valverde Reviewed-by: Michael Mann --- doc/README.dissector | 1 + epan/dissectors/packet-ipv6.c | 2 +- epan/ftypes/ftype-bytes.c | 2 +- epan/proto.c | 12 ++++++++++-- epan/proto.h | 1 + 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/doc/README.dissector b/doc/README.dissector index 0adf1ca951..11acb0507e 100644 --- a/doc/README.dissector +++ b/doc/README.dissector @@ -141,6 +141,7 @@ FIELDDISPLAY --For FT_UINT{8,16,24,32,40,48,56,64} and SEP_DOT, SEP_DASH, SEP_COLON, or SEP_SPACE to provide a separator between bytes. BASE_NONE has no separator between bytes + BASE_ALLOW_ZERO displays instead of for zero sized byte array --For FT_IPv4: diff --git a/epan/dissectors/packet-ipv6.c b/epan/dissectors/packet-ipv6.c index 8d992cae36..f778e090d5 100644 --- a/epan/dissectors/packet-ipv6.c +++ b/epan/dissectors/packet-ipv6.c @@ -2744,7 +2744,7 @@ proto_register_ipv6(void) }, { &hf_ipv6_opt_padn, { "PadN", "ipv6.opt.padn", - FT_BYTES, BASE_NONE, NULL, 0x0, + FT_BYTES, BASE_NONE|BASE_ALLOW_ZERO, NULL, 0x0, "PadN Option", HFILL } }, { &hf_ipv6_opt_rtalert, diff --git a/epan/ftypes/ftype-bytes.c b/epan/ftypes/ftype-bytes.c index 008772b7cf..0733681dd2 100644 --- a/epan/ftypes/ftype-bytes.c +++ b/epan/ftypes/ftype-bytes.c @@ -142,7 +142,7 @@ bytes_to_repr(fvalue_t *fv, ftrepr_t rtype, int field_display, char *buf) { char separator; - switch(field_display) + switch(FIELD_DISPLAY(field_display)) { case SEP_DOT: separator = '.'; diff --git a/epan/proto.c b/epan/proto.c index 0fe4b320c7..28d3677f5e 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -4635,7 +4635,11 @@ proto_custom_set(proto_tree* tree, GSList *field_ids, gint occurrence, wmem_free(NULL, str); } else { - offset_r += protoo_strlcpy(result+offset_r, "", size-offset_r); + if (hfinfo->display & BASE_ALLOW_ZERO) { + offset_r += protoo_strlcpy(result+offset_r, "", size-offset_r); + } else { + offset_r += protoo_strlcpy(result+offset_r, "", size-offset_r); + } } break; @@ -6631,7 +6635,11 @@ proto_item_fill_label(field_info *fi, gchar *label_str) label_fill(label_str, 0, hfinfo, str); wmem_free(NULL, str); } else { - label_fill(label_str, 0, hfinfo, ""); + if (hfinfo->display & BASE_ALLOW_ZERO) { + label_fill(label_str, 0, hfinfo, ""); + } else { + label_fill(label_str, 0, hfinfo, ""); + } } break; diff --git a/epan/proto.h b/epan/proto.h index c5e840237a..c6ce7ede21 100644 --- a/epan/proto.h +++ b/epan/proto.h @@ -538,6 +538,7 @@ typedef enum { #define BASE_RANGE_STRING 0x100 #define BASE_EXT_STRING 0x200 #define BASE_VAL64_STRING 0x400 +#define BASE_ALLOW_ZERO 0x800 /**< Display instead of for zero sized byte array */ /** BASE_ values that cause the field value to be displayed twice */ #define IS_BASE_DUAL(b) ((b)==BASE_DEC_HEX||(b)==BASE_HEX_DEC)