From 16a61cc9c068f03ae5faf9e59dd7b185a3056b29 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Fri, 31 Dec 2004 20:35:55 +0000 Subject: Note what Fibre Channel spec documents this protocol. Don't assign the const pointers passed to hash routines to non-const pointers. Don't assume that strings the spec says are null-terminated are necessarily null-terminated in the packet - use "tvb_strsize()" to find the length of the purported null-terminated string; it'll throw the appropriate exception if no null is found. svn path=/trunk/; revision=12904 --- epan/dissectors/packet-fcfcs.c | 67 +++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 40 deletions(-) (limited to 'epan/dissectors/packet-fcfcs.c') diff --git a/epan/dissectors/packet-fcfcs.c b/epan/dissectors/packet-fcfcs.c index 179e9f1e66..09384be15c 100644 --- a/epan/dissectors/packet-fcfcs.c +++ b/epan/dissectors/packet-fcfcs.c @@ -58,6 +58,10 @@ #include "packet-fcct.h" #include "packet-fcfcs.h" +/* + * See the FC-GS3 specification. + */ + /* Initialize the protocol and registered fields */ static int proto_fcfcs = -1; static int hf_fcs_opcode = -1; @@ -117,8 +121,8 @@ static dissector_handle_t data_handle; static gint fcfcs_equal(gconstpointer v, gconstpointer w) { - fcfcs_conv_key_t *v1 = (fcfcs_conv_key_t *)v; - fcfcs_conv_key_t *v2 = (fcfcs_conv_key_t *)w; + const fcfcs_conv_key_t *v1 = v; + const fcfcs_conv_key_t *v2 = w; return (v1->conv_idx == v2->conv_idx); } @@ -126,7 +130,7 @@ fcfcs_equal(gconstpointer v, gconstpointer w) static guint fcfcs_hash (gconstpointer v) { - fcfcs_conv_key_t *key = (fcfcs_conv_key_t *)v; + const fcfcs_conv_key_t *key = v; guint val; val = key->conv_idx; @@ -299,7 +303,6 @@ static void dissect_fcfcs_gieil (tvbuff_t *tvb, proto_tree *tree, gboolean isreq) { int offset = 16; /* past the fcct header */ - gchar *str; int len, tot_len, prevlen; if (tree) { @@ -313,43 +316,28 @@ dissect_fcfcs_gieil (tvbuff_t *tvb, proto_tree *tree, gboolean isreq) tot_len); prevlen = 0; - str = (gchar *)tvb_get_ptr (tvb, offset+4, tot_len); - len = strlen (str); - if (len) { - proto_tree_add_item (tree, hf_fcs_vendorname, tvb, offset+4, - len, 0); - } - - prevlen += (len+1); - str = (gchar *)tvb_get_ptr (tvb, offset+4+prevlen, tot_len-prevlen); - len = strlen (str); - - if (len) { - proto_tree_add_item (tree, hf_fcs_modelname, tvb, offset+4+prevlen, - len, 0); - } - - prevlen += (len+1); - str = (gchar *)tvb_get_ptr (tvb, offset+4+prevlen, tot_len-prevlen); - len = strlen (str); - - if (len) { - proto_tree_add_item (tree, hf_fcs_releasecode, tvb, - offset+4+prevlen, len, 0); - } - - prevlen += (len+1); + len = tvb_strsize(tvb, offset+4); + proto_tree_add_item (tree, hf_fcs_vendorname, tvb, offset+4, + len, FALSE); + prevlen += len; + + len = tvb_strsize(tvb, offset+4+prevlen); + proto_tree_add_item (tree, hf_fcs_modelname, tvb, offset+4+prevlen, + len, FALSE); + prevlen += len; + + len = tvb_strsize(tvb, offset+4+prevlen); + proto_tree_add_item (tree, hf_fcs_releasecode, tvb, + offset+4+prevlen, len, FALSE); + prevlen += len; offset += (4+prevlen); while (tot_len > prevlen) { - str = (gchar *)tvb_get_ptr (tvb, offset, tot_len-prevlen); - len = strlen (str); - if (len) { - proto_tree_add_text (tree, tvb, offset, len, - "Vendor-specific Information: %s", - str); - } - prevlen += (len+1); - offset += (len+1); + len = tvb_strsize(tvb, offset); + proto_tree_add_text (tree, tvb, offset, len, + "Vendor-specific Information: %s", + tvb_format_text(tvb, offset, len-1)); + prevlen += len; + offset += len; } } } @@ -1181,4 +1169,3 @@ proto_reg_handoff_fcfcs (void) data_handle = find_dissector ("data"); } - -- cgit v1.2.3