diff options
author | Guy Harris <guy@alum.mit.edu> | 2003-06-12 08:33:32 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2003-06-12 08:33:32 +0000 |
commit | ee97ce31966f61de148ad85cb229e76a88801b02 (patch) | |
tree | 22f7363da150c57eb593a2e5871033e8b8585437 | |
parent | 04a87185285865ae91f903662c4bc721f66c8d88 (diff) | |
download | wireshark-ee97ce31966f61de148ad85cb229e76a88801b02.tar.gz wireshark-ee97ce31966f61de148ad85cb229e76a88801b02.tar.bz2 wireshark-ee97ce31966f61de148ad85cb229e76a88801b02.zip |
Add new routines:
tvb_get_string() - takes a tvbuff, an offset, and a length as
arguments, allocates a buffer big enough to hold a string with
the specified number of bytes plus an added null terminator
(i.e., length+1), copies the specified number of bytes from the
tvbuff, at the specified offset, to that buffer and puts in a
null terminator, and returns a pointer to that buffer (or throws
an exception before allocating the buffer if that many bytes
aren't available in the tvbuff);
tvb_get_stringz() - takes a tvbuff, an offset, and a pointer to
a "gint" as arguments, gets the size of the null-terminated
string starting at the specified offset in the tvbuff (throwing
an exception if the null terminator isn't found), allocates a
buffer big enough to hold that string, copies the string to that
buffer, and returns a pointer to that buffer and stores the
length of the string (including the terminating null) in the
variable pointed to by the "gint" pointer.
Replace many pieces of code allocating a buffer and copying a string
with calls to "tvb_get_string()" (for one thing, "tvb_get_string()"
doesn't require you to remember that the argument to
"tvb_get_nstringz0()" is the size of the buffer into which you're
copying the string, which might be the length of the string to be copied
*plus 1*).
Don't use fixed-length buffers for null-terminated strings (even if the
code that generates those packets has a #define to limit the length of
the string). Use "tvb_get_stringz()", instead.
In some cases where a value is fetched but is only used to pass an
argument to a "proto_tree_add_XXX" routine, use "proto_tree_add_item()"
instead.
svn path=/trunk/; revision=7859
-rw-r--r-- | epan/proto.c | 17 | ||||
-rw-r--r-- | epan/tvbuff.c | 73 | ||||
-rw-r--r-- | epan/tvbuff.h | 22 | ||||
-rw-r--r-- | packet-aim.c | 5 | ||||
-rw-r--r-- | packet-dcerpc.c | 11 | ||||
-rw-r--r-- | packet-fix.c | 12 | ||||
-rw-r--r-- | packet-ppp.c | 66 | ||||
-rw-r--r-- | packet-quake.c | 245 | ||||
-rw-r--r-- | packet-sdp.c | 13 | ||||
-rw-r--r-- | packet-sip.c | 10 | ||||
-rw-r--r-- | packet-smb-browse.c | 14 | ||||
-rw-r--r-- | packet-smb-common.c | 20 | ||||
-rw-r--r-- | packet-smb-logon.c | 11 | ||||
-rw-r--r-- | packet-smb.c | 5 | ||||
-rw-r--r-- | packet-smpp.c | 12 | ||||
-rw-r--r-- | packet-telnet.c | 19 | ||||
-rw-r--r-- | plugins/gryphon/packet-gryphon.c | 10 |
17 files changed, 287 insertions, 278 deletions
diff --git a/epan/proto.c b/epan/proto.c index c04cc1d028..97050528a5 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -1,7 +1,7 @@ /* proto.c * Routines for protocol tree * - * $Id: proto.c,v 1.92 2003/06/11 21:48:39 guy Exp $ + * $Id: proto.c,v 1.93 2003/06/12 08:33:31 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -711,7 +711,8 @@ proto_tree_add_item(proto_tree *tree, int hfindex, tvbuff_t *tvb, /* This can throw an exception */ length = tvb_strsize(tvb, start); - /* This g_strdup'ed memory is freed in proto_tree_free_node() */ + /* This g_malloc'ed memory is freed + in proto_tree_free_node() */ string = g_malloc(length); tvb_memcpy(tvb, string, start, length); @@ -750,16 +751,10 @@ proto_tree_add_item(proto_tree *tree, int hfindex, tvbuff_t *tvb, * rather than null-terminated.) */ - /* This g_strdup'ed memory is freed + /* This g_malloc'ed memory is freed * in proto_tree_free_node() */ - string = g_malloc(length + 1); - - CLEANUP_PUSH(g_free, string); - - tvb_memcpy(tvb, string, start, length); - string[length] = '\0'; - - CLEANUP_POP; + string = tvb_get_string(tvb, start, + length); new_fi->length = length; } proto_tree_set_string(new_fi, string, TRUE); diff --git a/epan/tvbuff.c b/epan/tvbuff.c index ec66db45d7..3961868723 100644 --- a/epan/tvbuff.c +++ b/epan/tvbuff.c @@ -9,7 +9,7 @@ * the data of a backing tvbuff, or can be a composite of * other tvbuffs. * - * $Id: tvbuff.c,v 1.46 2003/06/09 07:27:42 guy Exp $ + * $Id: tvbuff.c,v 1.47 2003/06/12 08:33:31 guy Exp $ * * Copyright (c) 2000 by Gilbert Ramirez <gram@alumni.rice.edu> * @@ -107,6 +107,10 @@ struct tvbuff { }; static guint8* +ensure_contiguous_no_exception(tvbuff_t *tvb, gint offset, gint length, + int *exception); + +static guint8* ensure_contiguous(tvbuff_t *tvb, gint offset, gint length); /* We dole out tvbuff's from this memchunk. */ @@ -804,7 +808,8 @@ tvb_raw_offset(tvbuff_t *tvb) } static guint8* -composite_ensure_contiguous(tvbuff_t *tvb, guint abs_offset, guint abs_length) +composite_ensure_contiguous_no_exception(tvbuff_t *tvb, guint abs_offset, + guint abs_length) { guint i, num_members; tvb_comp_t *composite; @@ -831,8 +836,11 @@ composite_ensure_contiguous(tvbuff_t *tvb, guint abs_offset, guint abs_length) if (check_offset_length_no_exception(member_tvb, abs_offset - composite->start_offsets[i], abs_length, &member_offset, &member_length, NULL)) { + /* + * The range is, in fact, contiguous within member_tvb. + */ g_assert(!tvb->real_data); - return ensure_contiguous(member_tvb, member_offset, member_length); + return ensure_contiguous_no_exception(member_tvb, member_offset, member_length, NULL); } else { tvb->real_data = tvb_memdup(tvb, 0, -1); @@ -854,6 +862,10 @@ ensure_contiguous_no_exception(tvbuff_t *tvb, gint offset, gint length, return NULL; } + /* + * We know that all the data is present in the tvbuff, so + * no exceptions should be thrown. + */ if (tvb->real_data) { return tvb->real_data + abs_offset; } @@ -862,11 +874,11 @@ ensure_contiguous_no_exception(tvbuff_t *tvb, gint offset, gint length, case TVBUFF_REAL_DATA: g_assert_not_reached(); case TVBUFF_SUBSET: - return ensure_contiguous(tvb->tvbuffs.subset.tvb, + return ensure_contiguous_no_exception(tvb->tvbuffs.subset.tvb, abs_offset - tvb->tvbuffs.subset.offset, - abs_length); + abs_length, NULL); case TVBUFF_COMPOSITE: - return composite_ensure_contiguous(tvb, abs_offset, abs_length); + return composite_ensure_contiguous_no_exception(tvb, abs_offset, abs_length); } } @@ -1021,10 +1033,9 @@ tvb_memcpy(tvbuff_t *tvb, guint8* target, gint offset, gint length) * "tvb_ensure_bytes_exist()" and then allocates a buffer and copies * data to it. * - * Does anything depend on this routine treating -1 as meaning "to the - * end of the buffer"? If so, perhaps we need two routines, one that - * treats -1 as such, and one that checks for -1 and then calls this - * routine. + * "composite_ensure_contiguous_no_exception()" depends on -1 not being + * an error; does anything else depend on this routine treating -1 as + * meaning "to the end of the buffer"? */ guint8* tvb_memdup(tvbuff_t *tvb, gint offset, gint length) @@ -1687,6 +1698,48 @@ tvb_format_text(tvbuff_t *tvb, gint offset, gint size) } +/* + * Given a tvbuff, an offset, and a length, allocate a buffer big enough + * to hold a non-null-terminated string of that length at that offset, + * plus a trailing '\0', copy the string into it, and return a pointer + * to the string. + * + * Throws an exception if the tvbuff ends before the string does. + */ +guint8 * +tvb_get_string(tvbuff_t *tvb, gint offset, gint length) +{ + guint8 *ptr, *strbuf; + + ptr = ensure_contiguous(tvb, offset, length); + strbuf = g_malloc(length + 1); + if (length != 0) + memcpy(strbuf, ptr, length); + strbuf[length] = '\0'; + return strbuf; +} + +/* + * Given a tvbuff and an offset, with the offset assumed to refer to + * a null-terminated string, find the length of that string (and throw + * an exception if the tvbuff ends before we find the null), allocate + * a buffer big enough to hold the string, copy the string into it, + * and return a pointer to the string. Also return the length of the + * string (including the terminating null) through a pointer. + */ +guint8 * +tvb_get_stringz(tvbuff_t *tvb, gint offset, gint *lengthp) +{ + guint size; + guint8 *strptr; + + size = tvb_strsize(tvb, offset); + strptr = g_malloc(size); + tvb_memcpy(tvb, strptr, offset, size); + *lengthp = size; + return strptr; +} + /* Looks for a stringz (NUL-terminated string) in tvbuff and copies * no more than bufsize number of bytes, including terminating NUL, to buffer. * Returns length of string (not including terminating NUL), or -1 if the string was diff --git a/epan/tvbuff.h b/epan/tvbuff.h index 5a08bac7b5..6dd756a03c 100644 --- a/epan/tvbuff.h +++ b/epan/tvbuff.h @@ -9,7 +9,7 @@ * the data of a backing tvbuff, or can be a composite of * other tvbuffs. * - * $Id: tvbuff.h,v 1.32 2003/05/19 03:23:12 gerald Exp $ + * $Id: tvbuff.h,v 1.33 2003/06/12 08:33:31 guy Exp $ * * Copyright (c) 2000 by Gilbert Ramirez <gram@alumni.rice.edu> * @@ -318,6 +318,26 @@ extern char *tvb_fake_unicode(tvbuff_t *tvb, int offset, int len, */ extern guint8 * tvb_format_text(tvbuff_t *tvb, gint offset, gint size); +/* + * Given a tvbuff, an offset, and a length, allocate a buffer big enough + * to hold a non-null-terminated string of that length at that offset, + * plus a trailing '\0', copy the string into it, and return a pointer + * to the string. + * + * Throws an exception if the tvbuff ends before the string does. + */ +extern guint8 *tvb_get_string(tvbuff_t *tvb, gint offset, gint length); + +/* + * Given a tvbuff and an offset, with the offset assumed to refer to + * a null-terminated string, find the length of that string (and throw + * an exception if the tvbuff ends before we find the null), allocate + * a buffer big enough to hold the string, copy the string into it, + * and return a pointer to the string. Also return the length of the + * string (including the terminating null) through a pointer. + */ +extern guint8 *tvb_get_stringz(tvbuff_t *tvb, gint offset, gint *lengthp); + /* Looks for a stringz (NUL-terminated string) in tvbuff and copies * no more than bufsize number of bytes, including terminating NUL, to buffer. * Returns length of string (not including terminating NUL), or -1 if the string was diff --git a/packet-aim.c b/packet-aim.c index bf059f5a2d..8857265b7d 100644 --- a/packet-aim.c +++ b/packet-aim.c @@ -2,7 +2,7 @@ * Routines for AIM Instant Messenger (OSCAR) dissection * Copyright 2000, Ralf Hoelzer <ralf@well.com> * - * $Id: packet-aim.c,v 1.29 2003/05/19 03:23:10 gerald Exp $ + * $Id: packet-aim.c,v 1.30 2003/06/12 08:33:28 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -1744,8 +1744,7 @@ static int dissect_aim_tlv(tvbuff_t *tvb, packet_info *pinfo _U_, data types */ if (tmp[i].datatype == FT_STRING && length > 0) { guint8 *buf; - buf = g_malloc(length); - tvb_get_nstringz0(tvb, offset + 4, length, buf); + buf = tvb_get_string(tvb, offset + 4, length); ti1 = proto_tree_add_text(tree, tvb, offset, length + 4, "%s: %s", tmp[i].desc, buf); g_free(buf); diff --git a/packet-dcerpc.c b/packet-dcerpc.c index 4c9f172b23..3b171bcb80 100644 --- a/packet-dcerpc.c +++ b/packet-dcerpc.c @@ -2,7 +2,7 @@ * Routines for DCERPC packet disassembly * Copyright 2001, Todd Sabin <tas@webspan.net> * - * $Id: packet-dcerpc.c,v 1.128 2003/06/10 05:53:32 guy Exp $ + * $Id: packet-dcerpc.c,v 1.129 2003/06/12 08:33:29 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -1057,17 +1057,14 @@ dissect_ndr_cvstring(tvbuff_t *tvb, int offset, packet_info *pinfo, } } else { /* - * First, make sure the entire string is in the tvbuff, and throw - * an exception if it isn't. If the length is bogus, this should + * "tvb_get_string()" throws an exception if the entire string + * isn't in the tvbuff. If the length is bogus, this should * keep us from trying to allocate an immensely large buffer. * (It won't help if the length is *valid* but immensely large, * but that's another matter; in any case, that would happen only * if we had an immensely large tvbuff....) */ - tvb_ensure_bytes_exist(tvb, offset, buffer_len); - s = g_malloc(buffer_len + 1); - tvb_memcpy(tvb, s, offset, buffer_len); - s[buffer_len] = '\0'; + s = tvb_get_string(tvb, offset, buffer_len); if (tree && buffer_len) proto_tree_add_item(string_tree, hfindex, tvb, offset, buffer_len, drep[0] & 0x10); diff --git a/packet-fix.c b/packet-fix.c index 9a82d0fcab..fa5b245b50 100644 --- a/packet-fix.c +++ b/packet-fix.c @@ -2,7 +2,7 @@ * Routines for Financial Information eXchange (FIX) Protocol dissection * Copyright 2000, PC Drew <drewpc@ibsncentral.com> * - * $Id: packet-fix.c,v 1.5 2003/06/12 08:02:47 guy Exp $ + * $Id: packet-fix.c,v 1.6 2003/06/12 08:33:29 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -867,8 +867,7 @@ dissect_fix(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) col_clear(pinfo->cinfo, COL_INFO); } - value = g_malloc(value_len); - tvb_get_nstringz0(tvb, value_offset, value_len, value); + value = tvb_get_string(tvb, value_offset, value_len); if (check_col(pinfo->cinfo, COL_INFO)) { col_add_fstr(pinfo->cinfo, COL_INFO, "%s", (char *)g_datalist_get_data(&msg_types, value)); @@ -929,12 +928,10 @@ dissect_fix(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) packet. */ return TRUE; } - tag_str = g_malloc(tag_len); - tvb_get_nstringz0(tvb, field_offset, tag_len, tag_str); + tag_str = tvb_get_string(tvb, field_offset, tag_len); tag = atoi(tag_str); - value = g_malloc(value_len); - tvb_get_nstringz0(tvb, value_offset, value_len, value); + value = tvb_get_string(tvb, value_offset, value_len); switch(tag) { case 1: /* Field Account */ @@ -2912,6 +2909,7 @@ dissect_fix(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) proto_tree_add_string(fix_tree, hf_fix_SideComplianceID, tvb, offset, field_len, value); break; default: + /* XXX - it could be -1 if the tag isn't a number */ proto_tree_add_text(fix_tree, tvb, offset, field_len, "%i: %s", tag, value); break; } diff --git a/packet-ppp.c b/packet-ppp.c index b94d9bf145..73d94f0ac8 100644 --- a/packet-ppp.c +++ b/packet-ppp.c @@ -1,7 +1,8 @@ /* packet-ppp.c * Routines for ppp packet disassembly + * RFC 1661, RFC 1662 * - * $Id: packet-ppp.c,v 1.111 2003/05/19 03:23:11 gerald Exp $ + * $Id: packet-ppp.c,v 1.112 2003/06/12 08:33:29 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -295,7 +296,7 @@ const value_string ppp_vals[] = { {PPP_SPAP, "Shiva Password Authentication Protocol" }, {PPP_CBCP, "Callback Control Protocol" }, {PPP_BACP, "Bandwidth Allocation Control Protocol" }, - {PPP_BAP, "Bandwitdh Allocation Protocol" }, + {PPP_BAP, "Bandwidth Allocation Protocol" }, {PPP_CONTCP, "Container Control Protocol" }, {PPP_CHAP, "Challenge Handshake Authentication Protocol" }, {PPP_RSAAP, "RSA Authentication Protocol" }, @@ -2095,9 +2096,7 @@ dissect_cbcp_callback_opt(const ip_tcp_opt *optp, tvbuff_t *tvb, proto_item *ta; proto_tree *addr_tree; guint8 addr_type; - gint addr_len; - guint8 buf[256]; /* Since length field in Callback Conf Option is - 8 bits, 256-octet buf is large enough. */ + guint addr_len; tf = proto_tree_add_text(tree, tvb, offset, length, "%s", optp->name); field_tree = proto_item_add_subtree(tf, *optp->subtree_index); @@ -2117,9 +2116,12 @@ dissect_cbcp_callback_opt(const ip_tcp_opt *optp, tvbuff_t *tvb, ((addr_type == 1) ? "PSTN/ISDN" : "Other"), addr_type); offset++; length--; - addr_len = tvb_get_nstringz0(tvb, offset, sizeof(buf), buf); - proto_tree_add_text(addr_tree, tvb, offset, addr_len + 1, - "Address: %s", buf); + addr_len = tvb_strsize(tvb, offset); + proto_tree_add_text(addr_tree, tvb, offset, addr_len, + "Address: %s", + addr_len == 1 ? + "" : + tvb_format_text(tvb, offset, addr_len - 1)); offset += (addr_len + 1); length -= (addr_len + 1); } @@ -2171,8 +2173,6 @@ dissect_bap_phone_delta_opt(const ip_tcp_opt *optp, tvbuff_t *tvb, proto_tree *suboption_tree; guint8 subopt_type; guint8 subopt_len; - guint8 buf[256]; /* Since Sub-Option length field in BAP Phone-Delta - Option is 8 bits, 256-octets buf is large enough */ tf = proto_tree_add_text(tree, tvb, offset, length, "%s", optp->name); field_tree = proto_item_add_subtree(tf, *optp->subtree_index); @@ -2203,9 +2203,9 @@ dissect_bap_phone_delta_opt(const ip_tcp_opt *optp, tvbuff_t *tvb, break; case BAP_PHONE_DELTA_SUBOPT_SUBSC_NUM: if (subopt_len > 2) { - tvb_get_nstringz0(tvb, offset + 2, subopt_len - 2, buf); proto_tree_add_text(suboption_tree, tvb, offset + 2, subopt_len - 2, - "Subscriber Number: %s", buf); + "Subscriber Number: %s", + tvb_format_text(tvb, offset + 2, subopt_len - 2)); } else { proto_tree_add_text(suboption_tree, tvb, offset + 1, 1, "Invalid suboption length: %u", subopt_len); @@ -2213,9 +2213,9 @@ dissect_bap_phone_delta_opt(const ip_tcp_opt *optp, tvbuff_t *tvb, break; case BAP_PHONE_DELTA_SUBOPT_PHONENUM_SUBADDR: if (subopt_len > 2) { - tvb_get_nstringz0(tvb, offset + 2, subopt_len - 2, buf); proto_tree_add_text(suboption_tree, tvb, offset + 2, subopt_len - 2, - "Phone Number Sub Address: %s", buf); + "Phone Number Sub Address: %s", + tvb_format_text(tvb, offset + 2, subopt_len - 2)); } break; default: @@ -2233,13 +2233,10 @@ dissect_bap_reason_opt(const ip_tcp_opt *optp, tvbuff_t *tvb, int offset, guint length, packet_info *pinfo _U_, proto_tree *tree) { - guint8 buf[256]; /* Since length field in BAP Reason Option is - 8 bits, 256-octets buf is large enough */ - if (length > 2) { - tvb_get_nstringz0(tvb, offset + 2, length - 2, buf); proto_tree_add_text(tree, tvb, offset, length, "%s: %s", - optp->name, buf); + optp->name, + tvb_format_text(tvb, offset + 2, length - 2)); } } @@ -2474,6 +2471,9 @@ dissect_lcp_options(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) -1, pinfo, tree); } +/* + * RFC 1661. + */ static void dissect_lcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { @@ -2481,6 +2481,9 @@ dissect_lcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) lcp_opts, N_LCP_OPTS, pinfo, tree); } +/* + * RFC 1332. + */ static void dissect_ipcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { @@ -2488,6 +2491,9 @@ dissect_ipcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) ipcp_opts, N_IPCP_OPTS, pinfo, tree); } +/* + * RFC 1962. + */ static void dissect_ccp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { @@ -2495,6 +2501,11 @@ dissect_ccp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) ccp_opts, N_CCP_OPTS, pinfo, tree); } +/* + * Callback Control Protocol - see + * + * http://www.linet.gr.jp/~manabe/PPxP/doc/Standards/draft-gidwani-ppp-callback-cp-00.txt + */ static void dissect_cbcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { @@ -2502,6 +2513,9 @@ dissect_cbcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) cbcp_opts, N_CBCP_OPTS, pinfo, tree); } +/* + * RFC 2125 (BACP and BAP). + */ static void dissect_bacp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { @@ -2512,7 +2526,6 @@ dissect_bacp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) static void dissect_bap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { - proto_item *ti; proto_tree *fh_tree = NULL; proto_item *tf; @@ -2590,6 +2603,9 @@ dissect_comp_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) } } +/* + * RFC 3153 (both PPPMuxCP and PPPMux). + */ static void dissect_pppmuxcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { @@ -2697,6 +2713,9 @@ dissect_pppmux(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) } /* if tree */ } +/* + * RFC 3032. + */ static void dissect_mplscp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { @@ -2704,6 +2723,10 @@ dissect_mplscp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) NULL, 0, pinfo, tree); } +/* + * Cisco Discovery Protocol Control Protocol. + * XXX - where is this documented? + */ static void dissect_cdpcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { @@ -3193,6 +3216,9 @@ dissect_chap( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree ) { } } +/* + * RFC 2472. + */ static void dissect_ipv6cp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { diff --git a/packet-quake.c b/packet-quake.c index 52cc1f4a59..715c06efc7 100644 --- a/packet-quake.c +++ b/packet-quake.c @@ -4,7 +4,7 @@ * Uwe Girlich <uwe@planetquake.com> * http://www.idsoftware.com/q1source/q1source.zip * - * $Id: packet-quake.c,v 1.29 2003/05/19 03:23:11 gerald Exp $ + * $Id: packet-quake.c,v 1.30 2003/06/12 08:33:29 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -155,18 +155,18 @@ static void dissect_quake_CCREQ_CONNECT (tvbuff_t *tvb, proto_tree *tree) { - char game[QUAKE_MAXSTRING]; - guint8 version; - gint len; + gint offset; + proto_item *ti; - len = tvb_get_nstringz0(tvb, 0, sizeof(game), game); - version = tvb_get_guint8(tvb, len + 1); + offset = 0; if (tree) { - proto_tree_add_string(tree, hf_quake_CCREQ_CONNECT_game, - tvb, 0, len + 1, game); - proto_tree_add_uint(tree, hf_quake_CCREQ_CONNECT_version, - tvb, len + 1, 1, version); + ti = proto_tree_add_item(tree, hf_quake_CCREQ_CONNECT_game, + tvb, offset, -1, TRUE); + offset += proto_item_get_len(ti); + + proto_tree_add_item(tree, hf_quake_CCREQ_CONNECT_version, + tvb, offset, 1, TRUE); } } @@ -175,18 +175,17 @@ static void dissect_quake_CCREQ_SERVER_INFO (tvbuff_t *tvb, proto_tree *tree) { - char game[QUAKE_MAXSTRING]; - guint8 version; - gint len; + gint offset; + proto_item *ti; - len = tvb_get_nstringz0(tvb, 0, sizeof(game), game); - version = tvb_get_guint8(tvb, len + 1); + offset = 0; if (tree) { - proto_tree_add_string(tree, hf_quake_CCREQ_SERVER_INFO_game, - tvb, 0, len + 1, game); - proto_tree_add_uint(tree, hf_quake_CCREQ_SERVER_INFO_version, - tvb, len + 1, 1, version); + ti = proto_tree_add_item(tree, hf_quake_CCREQ_SERVER_INFO_game, + tvb, offset, -1, TRUE); + offset += proto_item_get_len(ti); + proto_tree_add_item(tree, hf_quake_CCREQ_SERVER_INFO_version, + tvb, offset, 1, TRUE); } } @@ -195,12 +194,9 @@ static void dissect_quake_CCREQ_PLAYER_INFO (tvbuff_t *tvb, proto_tree *tree) { - guint8 player; - - player = tvb_get_guint8(tvb, 0); if (tree) { - proto_tree_add_uint(tree, hf_quake_CCREQ_PLAYER_INFO_player, - tvb, 0, 1, player); + proto_tree_add_item(tree, hf_quake_CCREQ_PLAYER_INFO_player, + tvb, 0, 1, TRUE); } } @@ -209,13 +205,9 @@ static void dissect_quake_CCREQ_RULE_INFO (tvbuff_t *tvb, proto_tree *tree) { - char rule[QUAKE_MAXSTRING]; - gint len; - - len = tvb_get_nstringz0(tvb, 0, sizeof(rule), rule); if (tree) { - proto_tree_add_string(tree, hf_quake_CCREQ_RULE_INFO_lastrule, - tvb, 0, len + 1, rule); + proto_tree_add_item(tree, hf_quake_CCREQ_RULE_INFO_lastrule, + tvb, 0, -1, TRUE); } } @@ -244,14 +236,9 @@ static void dissect_quake_CCREP_REJECT (tvbuff_t *tvb, proto_tree *tree) { - char reason[QUAKE_MAXSTRING]; - gint len; - - len = tvb_get_nstringz0(tvb, 0, sizeof(reason), reason); - if (tree) { - proto_tree_add_string(tree, hf_quake_CCREP_REJECT_reason, - tvb, 0, len + 1, reason); + proto_tree_add_item(tree, hf_quake_CCREP_REJECT_reason, + tvb, 0, -1, TRUE); } } @@ -261,49 +248,33 @@ dissect_quake_CCREP_SERVER_INFO (tvbuff_t *tvb, proto_tree *tree) { gint offset; - gint len; - char address[QUAKE_MAXSTRING]; - char server[QUAKE_MAXSTRING]; - char map[QUAKE_MAXSTRING]; - - guint8 num_player; - guint8 max_player; - guint8 version; + proto_item *ti; offset = 0; - len = tvb_get_nstringz0(tvb, offset, sizeof(address), address); - if (tree) { - proto_tree_add_string(tree, hf_quake_CCREP_SERVER_INFO_address, - tvb, offset, len + 1, address); - } - offset += len + 1; - - len = tvb_get_nstringz0(tvb, offset, sizeof(server), server); - if (tree) { - proto_tree_add_string(tree, hf_quake_CCREP_SERVER_INFO_server, - tvb, offset, len + 1, server); - } - offset += len + 1; - - len = tvb_get_nstringz0(tvb, offset, sizeof(map), map); - if (tree) { - proto_tree_add_string(tree, hf_quake_CCREP_SERVER_INFO_map, - tvb, offset, len + 1, map); - } - offset += len + 1; - - num_player = tvb_get_guint8(tvb, offset + 0); - max_player = tvb_get_guint8(tvb, offset + 1); - version = tvb_get_guint8(tvb, offset + 2); - if (tree) { - proto_tree_add_uint(tree, hf_quake_CCREP_SERVER_INFO_num_player, - tvb, offset + 0, 1, num_player); - proto_tree_add_uint(tree, hf_quake_CCREP_SERVER_INFO_max_player, - tvb, offset + 1, 1, max_player); - proto_tree_add_uint(tree, hf_quake_CCREQ_SERVER_INFO_version, - tvb, offset + 2, 1, version); + ti = proto_tree_add_item(tree, + hf_quake_CCREP_SERVER_INFO_address, tvb, offset, -1, + TRUE); + offset += proto_item_get_len(ti); + + ti = proto_tree_add_item(tree, + hf_quake_CCREP_SERVER_INFO_server, tvb, offset, -1, + TRUE); + offset += proto_item_get_len(ti); + + ti = proto_tree_add_item(tree, hf_quake_CCREP_SERVER_INFO_map, + tvb, offset, -1, TRUE); + offset += proto_item_get_len(ti); + + proto_tree_add_item(tree, hf_quake_CCREP_SERVER_INFO_num_player, + tvb, offset, 1, TRUE); + offset += 1; + proto_tree_add_item(tree, hf_quake_CCREP_SERVER_INFO_max_player, + tvb, offset, 1, TRUE); + offset += 1; + proto_tree_add_item(tree, hf_quake_CCREQ_SERVER_INFO_version, + tvb, offset, 1, TRUE); } } @@ -313,67 +284,50 @@ dissect_quake_CCREP_PLAYER_INFO (tvbuff_t *tvb, proto_tree *tree) { gint offset; - guint8 player; - gint len; - char name[QUAKE_MAXSTRING]; + proto_item *ti; guint32 colors; guint32 color_shirt; guint32 color_pants; - guint32 frags; - guint32 connect_time; - char address[QUAKE_MAXSTRING]; + proto_item *colors_item; + proto_tree *colors_tree; offset = 0; - player = tvb_get_guint8(tvb, offset); if (tree) { - proto_tree_add_uint(tree, hf_quake_CCREQ_PLAYER_INFO_player, - tvb, offset, 1, player); - } - offset += 1; + proto_tree_add_item(tree, hf_quake_CCREQ_PLAYER_INFO_player, + tvb, offset, 1, TRUE); + offset += 1; - len = tvb_get_nstringz0(tvb, offset, sizeof(name), name); - if (tree) { - proto_tree_add_string(tree, hf_quake_CCREP_PLAYER_INFO_name, - tvb, offset, len + 1, name); - } - offset += len + 1; + ti = proto_tree_add_item(tree, hf_quake_CCREP_PLAYER_INFO_name, + tvb, offset, -1, TRUE); + offset += proto_item_get_len(ti); - colors = tvb_get_letohl(tvb, offset + 0); - color_shirt = (colors >> 4) & 0x0f; - color_pants = (colors ) & 0x0f; - frags = tvb_get_letohl(tvb, offset + 4); - connect_time = tvb_get_letohl(tvb, offset + 8); - if (tree) { - proto_item *colors_item; - proto_tree *colors_tree; + colors = tvb_get_letohl(tvb, offset + 0); + color_shirt = (colors >> 4) & 0x0f; + color_pants = (colors ) & 0x0f; colors_item = proto_tree_add_uint(tree, hf_quake_CCREP_PLAYER_INFO_colors, - tvb, offset + 0, 4, colors); - if (colors_item) { - colors_tree = proto_item_add_subtree(colors_item, - ett_quake_control_colors); - proto_tree_add_uint(colors_tree, - hf_quake_CCREP_PLAYER_INFO_colors_shirt, - tvb, offset + 0, 1, color_shirt); - proto_tree_add_uint(colors_tree, - hf_quake_CCREP_PLAYER_INFO_colors_pants, - tvb, offset + 0, 1, color_pants); - } - proto_tree_add_uint(tree, hf_quake_CCREP_PLAYER_INFO_frags, - tvb, offset + 4, 4, frags); - proto_tree_add_uint(tree, hf_quake_CCREP_PLAYER_INFO_connect_time, - tvb, offset + 8, 4, connect_time); + tvb, offset, 4, colors); + colors_tree = proto_item_add_subtree(colors_item, + ett_quake_control_colors); + proto_tree_add_uint(colors_tree, + hf_quake_CCREP_PLAYER_INFO_colors_shirt, + tvb, offset, 1, color_shirt); + proto_tree_add_uint(colors_tree, + hf_quake_CCREP_PLAYER_INFO_colors_pants, + tvb, offset, 1, color_pants); + offset += 4; + proto_tree_add_item(tree, hf_quake_CCREP_PLAYER_INFO_frags, + tvb, offset, 4, TRUE); + offset += 4; + proto_tree_add_item(tree, hf_quake_CCREP_PLAYER_INFO_connect_time, + tvb, offset, 4, TRUE); + offset += 4; + + proto_tree_add_item(tree, hf_quake_CCREP_PLAYER_INFO_address, + tvb, offset, -1, TRUE); } - offset += 3*4; - - len = tvb_get_nstringz0(tvb, offset, sizeof(address), address); - if (tree) { - proto_tree_add_string(tree, hf_quake_CCREP_PLAYER_INFO_address, - tvb, offset, len + 1, address); - } - offset += len + 1; } @@ -381,28 +335,21 @@ static void dissect_quake_CCREP_RULE_INFO (tvbuff_t *tvb, proto_tree *tree) { - char rule[QUAKE_MAXSTRING]; - char value[QUAKE_MAXSTRING]; - gint len; gint offset; + proto_item *ti; - if (tvb_length(tvb) == 0) return; + if (tvb_reported_length(tvb) == 0) return; offset = 0; - len = tvb_get_nstringz0(tvb, offset, sizeof(rule), rule); if (tree) { - proto_tree_add_string(tree, hf_quake_CCREP_RULE_INFO_rule, - tvb, offset, len + 1, rule); - } - offset += len + 1; + ti = proto_tree_add_item(tree, hf_quake_CCREP_RULE_INFO_rule, + tvb, offset, -1, TRUE); + offset += proto_item_get_len(ti); - len = tvb_get_nstringz0(tvb, offset, sizeof(value), value); - if (tree) { - proto_tree_add_string(tree, hf_quake_CCREP_RULE_INFO_value, - tvb, offset, len + 1, value); + proto_tree_add_item(tree, hf_quake_CCREP_RULE_INFO_value, + tvb, offset, -1, TRUE); } - offset += len + 1; } @@ -608,7 +555,7 @@ proto_register_quake(void) "Control Command", HFILL }}, { &hf_quake_CCREQ_CONNECT_game, { "Game", "quake.control.connect.game", - FT_STRING, BASE_DEC, NULL, 0x0, + FT_STRINGZ, BASE_NONE, NULL, 0x0, "Game Name", HFILL }}, { &hf_quake_CCREQ_CONNECT_version, { "Version", "quake.control.connect.version", @@ -616,7 +563,7 @@ proto_register_quake(void) "Game Protocol Version Number", HFILL }}, { &hf_quake_CCREQ_SERVER_INFO_game, { "Game", "quake.control.server_info.game", - FT_STRING, BASE_DEC, NULL, 0x0, + FT_STRINGZ, BASE_NONE, NULL, 0x0, "Game Name", HFILL }}, { &hf_quake_CCREQ_SERVER_INFO_version, { "Version", "quake.control.server_info.version", @@ -628,7 +575,7 @@ proto_register_quake(void) "Player", HFILL }}, { &hf_quake_CCREQ_RULE_INFO_lastrule, { "Last Rule", "quake.control.rule_info.lastrule", - FT_STRING, BASE_DEC, NULL, 0x0, + FT_STRINGZ, BASE_NONE, NULL, 0x0, "Last Rule Name", HFILL }}, { &hf_quake_CCREP_ACCEPT_port, { "Port", "quake.control.accept.port", @@ -636,19 +583,19 @@ proto_register_quake(void) "Game Data Port", HFILL }}, { &hf_quake_CCREP_REJECT_reason, { "Reason", "quake.control.reject.reason", - FT_STRING, BASE_DEC, NULL, 0x0, + FT_STRINGZ, BASE_NONE, NULL, 0x0, "Reject Reason", HFILL }}, { &hf_quake_CCREP_SERVER_INFO_address, { "Address", "quake.control.server_info.address", - FT_STRING, BASE_DEC, NULL, 0x0, + FT_STRINGZ, BASE_NONE, NULL, 0x0, "Server Address", HFILL }}, { &hf_quake_CCREP_SERVER_INFO_server, { "Server", "quake.control.server_info.server", - FT_STRING, BASE_DEC, NULL, 0x0, + FT_STRINGZ, BASE_NONE, NULL, 0x0, "Server Name", HFILL }}, { &hf_quake_CCREP_SERVER_INFO_map, { "Map", "quake.control.server_info.map", - FT_STRING, BASE_DEC, NULL, 0x0, + FT_STRINGZ, BASE_NONE, NULL, 0x0, "Map Name", HFILL }}, { &hf_quake_CCREP_SERVER_INFO_num_player, { "Number of Players", "quake.control.server_info.num_player", @@ -660,7 +607,7 @@ proto_register_quake(void) "Maximal Number of Players", HFILL }}, { &hf_quake_CCREP_PLAYER_INFO_name, { "Name", "quake.control.player_info.name", - FT_STRING, BASE_DEC, NULL, 0x0, + FT_STRINGZ, BASE_NONE, NULL, 0x0, "Player Name", HFILL }}, { &hf_quake_CCREP_PLAYER_INFO_colors, { "Colors", "quake.control.player_info.colors", @@ -684,15 +631,15 @@ proto_register_quake(void) "Player Connect Time", HFILL }}, { &hf_quake_CCREP_PLAYER_INFO_address, { "Address", "quake.control.player_info.address", - FT_STRING, BASE_DEC, NULL, 0x0, + FT_STRINGZ, BASE_NONE, NULL, 0x0, "Player Address", HFILL }}, { &hf_quake_CCREP_RULE_INFO_rule, { "Rule", "quake.control.rule_info.rule", - FT_STRING, BASE_DEC, NULL, 0x0, + FT_STRINGZ, BASE_NONE, NULL, 0x0, "Rule Name", HFILL }}, { &hf_quake_CCREP_RULE_INFO_value, { "Value", "quake.control.rule_info.value", - FT_STRING, BASE_DEC, NULL, 0x0, + FT_STRINGZ, BASE_NONE, NULL, 0x0, "Rule Value", HFILL }}, }; static gint *ett[] = { diff --git a/packet-sdp.c b/packet-sdp.c index 71cf27569e..301785b03c 100644 --- a/packet-sdp.c +++ b/packet-sdp.c @@ -4,7 +4,7 @@ * Jason Lango <jal@netapp.com> * Liberally copied from packet-http.c, by Guy Harris <guy@alum.mit.edu> * - * $Id: packet-sdp.c,v 1.33 2002/08/28 21:00:30 jmayer Exp $ + * $Id: packet-sdp.c,v 1.34 2003/06/12 08:33:29 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -272,20 +272,17 @@ dissect_sdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) break; } tokenoffset = 2; - if( hf == hf_unknown ) - tokenoffset = 0; - string = g_malloc(linelen - tokenoffset + 1); - CLEANUP_PUSH(g_free, string); - tvb_memcpy(tvb, (guint8 *)string, offset + tokenoffset, + if (hf == hf_unknown) + tokenoffset = 0; + string = tvb_get_string(tvb, offset + tokenoffset, linelen - tokenoffset); - string[linelen - tokenoffset] = '\0'; sub_ti = proto_tree_add_string_format(sdp_tree,hf,tvb, offset, linelen, string, "%s: %s", proto_registrar_get_name(hf), format_text(string, linelen - tokenoffset)); - CLEANUP_CALL_AND_POP; + g_free(string); call_sdp_subdissector(tvb_new_subset(tvb,offset+tokenoffset, linelen-tokenoffset,-1), hf,sub_ti); diff --git a/packet-sip.c b/packet-sip.c index 6cee21d410..fac7985964 100644 --- a/packet-sip.c +++ b/packet-sip.c @@ -17,7 +17,7 @@ * Copyright 2000, Heikki Vatiainen <hessu@cs.tut.fi> * Copyright 2001, Jean-Francois Mule <jfm@cablelabs.com> * - * $Id: packet-sip.c,v 1.38 2003/06/11 21:17:41 guy Exp $ + * $Id: packet-sip.c,v 1.39 2003/06/12 08:33:29 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -443,10 +443,8 @@ dissect_sip_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, * Fetch the value. */ value_len = line_end_offset - value_offset; - value = g_malloc(value_len + 1); - tvb_memcpy(tvb, value, value_offset, + value = tvb_get_string(tvb, value_offset, value_len); - value[value_len] = '\0'; /* * Add it to the protocol tree, @@ -489,9 +487,7 @@ void dfilter_sip_request_line(tvbuff_t *tvb, proto_tree *tree, guint meth_len) * We know we have the entire method; otherwise, "sip_parse_line()" * would have returned OTHER_LINE. */ - string = g_malloc(meth_len + 1); - tvb_memcpy(tvb, (guint8 *)string, 0, meth_len); - string[meth_len] = '\0'; + string = tvb_get_string(tvb, 0, meth_len); proto_tree_add_string(tree, hf_Method, tvb, 0, meth_len, string); g_free(string); } diff --git a/packet-smb-browse.c b/packet-smb-browse.c index 408ff3c5c2..521fbe19f7 100644 --- a/packet-smb-browse.c +++ b/packet-smb-browse.c @@ -2,7 +2,7 @@ * Routines for SMB Browser packet dissection * Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com> * - * $Id: packet-smb-browse.c,v 1.30 2003/04/30 02:35:19 gerald Exp $ + * $Id: packet-smb-browse.c,v 1.31 2003/06/12 08:33:29 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -696,19 +696,13 @@ dissect_mailslot_browse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tr offset += 1; /* name of computer to which to send reply */ - namelen = tvb_strsize(tvb, offset); - proto_tree_add_item(tree, hf_response_computer_name, - tvb, offset, namelen, TRUE); - - computer_name = g_malloc(namelen); - tvb_get_nstringz0(tvb, offset, namelen, computer_name); - + computer_name = tvb_get_stringz(tvb, offset, &namelen); + proto_tree_add_string(tree, hf_response_computer_name, + tvb, offset, namelen, computer_name); if (check_col(pinfo->cinfo, COL_INFO)) col_append_fstr( pinfo->cinfo, COL_INFO, " %s", computer_name); - g_free(computer_name); - offset += namelen; break; } diff --git a/packet-smb-common.c b/packet-smb-common.c index 60c4c67724..153e807210 100644 --- a/packet-smb-common.c +++ b/packet-smb-common.c @@ -2,7 +2,7 @@ * Common routines for smb packet dissection * Copyright 2000, Jeffrey C. Foster <jfoste@woodward.com> * - * $Id: packet-smb-common.c,v 1.17 2003/05/09 01:41:28 tpot Exp $ + * $Id: packet-smb-common.c,v 1.18 2003/06/12 08:33:30 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -52,22 +52,12 @@ const value_string share_type_vals[] = { int display_ms_string(tvbuff_t *tvb, proto_tree *tree, int offset, int hf_index, char **data) { char *str; - int len; + gint len; /* display a string from the tree and return the new offset */ - len = tvb_strnlen(tvb, offset, -1); - if (len == -1) { - /* - * XXX - throw an exception? - */ - len = tvb_length_remaining(tvb, offset); - } - str = g_malloc(len+1); - tvb_memcpy(tvb, (guint8 *)str, offset, len); - str[len] = '\0'; - - proto_tree_add_string(tree, hf_index, tvb, offset, len+1, str); + str = tvb_get_stringz(tvb, offset, &len); + proto_tree_add_string(tree, hf_index, tvb, offset, len, str); /* Return a copy of the string if requested */ @@ -76,7 +66,7 @@ int display_ms_string(tvbuff_t *tvb, proto_tree *tree, int offset, int hf_index, else g_free(str); - return offset+len+1; + return offset+len; } diff --git a/packet-smb-logon.c b/packet-smb-logon.c index a26b68a5b5..a927de74f7 100644 --- a/packet-smb-logon.c +++ b/packet-smb-logon.c @@ -2,7 +2,7 @@ * Routines for SMB net logon packet dissection * Copyright 2000, Jeffrey C. Foster <jfoste@woodward.com> * - * $Id: packet-smb-logon.c,v 1.33 2003/05/21 10:16:10 sahlberg Exp $ + * $Id: packet-smb-logon.c,v 1.34 2003/06/12 08:33:30 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -310,18 +310,17 @@ dissect_smb_logon_LM20_resp(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *t static int dissect_smb_pdc_query(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset) { - char *name = NULL; + char *name; /*** 0x07 Query for Primary PDC ***/ /* computer name */ offset = display_ms_string(tvb, tree, offset, hf_computer_name, &name); - if (name && check_col(pinfo->cinfo, COL_INFO)) { + if (check_col(pinfo->cinfo, COL_INFO)) col_append_fstr(pinfo->cinfo, COL_INFO, " from %s", name); - g_free(name); - name = NULL; - } + + g_free(name); /* mailslot name */ offset = display_ms_string(tvb, tree, offset, hf_mailslot_name, NULL); diff --git a/packet-smb.c b/packet-smb.c index b216338d24..0f45ce79fd 100644 --- a/packet-smb.c +++ b/packet-smb.c @@ -3,7 +3,7 @@ * Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com> * 2001 Rewrite by Ronnie Sahlberg and Guy Harris * - * $Id: packet-smb.c,v 1.352 2003/06/10 05:28:02 guy Exp $ + * $Id: packet-smb.c,v 1.353 2003/06/12 08:33:30 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -10736,8 +10736,7 @@ dissect_4_2_16_2(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, /* EA name */ - name = g_malloc(name_len + 1); - tvb_get_nstringz(tvb, offset, name_len + 1, name); + name = tvb_get_string(tvb, offset, name_len); proto_item_append_text(item, ": %s", name); g_free(name); diff --git a/packet-smpp.c b/packet-smpp.c index 996f1a59cc..3750b491f4 100644 --- a/packet-smpp.c +++ b/packet-smpp.c @@ -2,7 +2,7 @@ * Routines for Short Message Peer to Peer dissection * Copyright 2001, Tom Uijldert <tom.uijldert@cmg.nl> * - * $Id: packet-smpp.c,v 1.11 2003/06/06 01:56:39 guy Exp $ + * $Id: packet-smpp.c,v 1.12 2003/06/12 08:33:30 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -572,7 +572,7 @@ static const value_string vals_its_session_ind[] = { * \retval FALSE Absolute time */ static gboolean -smpp_mktime(char *datestr, time_t *secs, int *nsecs) +smpp_mktime(const char *datestr, time_t *secs, int *nsecs) { struct tm r_time; time_t t_diff; @@ -616,7 +616,7 @@ smpp_mktime(char *datestr, time_t *secs, int *nsecs) static void smpp_handle_string(proto_tree *tree, tvbuff_t *tvb, int field, int *offset) { - gint len; + guint len; len = tvb_strsize(tvb, *offset); if (len > 1) { @@ -660,12 +660,11 @@ static void smpp_handle_time(proto_tree *tree, tvbuff_t *tvb, int field, int field_R, int *offset) { - char strval[BUFSIZ]; + char *strval; gint len; nstime_t tmptime; - len = tvb_get_nstringz(tvb, *offset, BUFSIZ, strval); - len++; + strval = tvb_get_stringz(tvb, *offset, &len); if (*strval) { if (smpp_mktime(strval, &tmptime.secs, &tmptime.nsecs)) @@ -673,6 +672,7 @@ smpp_handle_time(proto_tree *tree, tvbuff_t *tvb, else proto_tree_add_time(tree, field, tvb, *offset, len, &tmptime); } + g_free(strval); *offset += len; } diff --git a/packet-telnet.c b/packet-telnet.c index 53002a7c40..601998e7ae 100644 --- a/packet-telnet.c +++ b/packet-telnet.c @@ -2,7 +2,7 @@ * Routines for Telnet packet dissection; see RFC 854 and RFC 855 * Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com> * - * $Id: packet-telnet.c,v 1.40 2003/04/30 02:35:20 gerald Exp $ + * $Id: packet-telnet.c,v 1.41 2003/06/12 08:33:30 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -406,9 +406,8 @@ dissect_comport_subopt(const char *optname, tvbuff_t *tvb, int offset, int len, if (len == 0) { proto_tree_add_text(tree, tvb, offset, 1, "%s Requests Signature",source); } else { - guint8 *sig = g_malloc(len); - gint siglen = tvb_get_nstringz0(tvb, offset+1, len, sig); - proto_tree_add_text(tree, tvb, offset, 1 + siglen, "%s Signature: %s",source, sig); + guint8 *sig = tvb_get_string(tvb, offset + 1, len); + proto_tree_add_text(tree, tvb, offset, 1 + len, "%s Signature: %s",source, sig); g_free(sig); } break; @@ -416,7 +415,7 @@ dissect_comport_subopt(const char *optname, tvbuff_t *tvb, int offset, int len, case TNCOMPORT_SETBAUDRATE: len--; if (len >= 4) { - guint32 baud = tvb_get_ntohl(tvb, offset+1); + guint32 baud = tvb_get_ntohl(tvb, offset+1); if (baud == 0) { proto_tree_add_text(tree, tvb, offset, 5, "%s Requests Baud Rate",source); } else { @@ -430,7 +429,7 @@ dissect_comport_subopt(const char *optname, tvbuff_t *tvb, int offset, int len, case TNCOMPORT_SETDATASIZE: len--; if (len >= 1) { - guint8 datasize = tvb_get_guint8(tvb, offset+1); + guint8 datasize = tvb_get_guint8(tvb, offset+1); const char *ds = (datasize > 8) ? "<invalid>" : datasizes[datasize]; proto_tree_add_text(tree, tvb, offset, 2, "%s Data Size: %s",source,ds); } else { @@ -441,7 +440,7 @@ dissect_comport_subopt(const char *optname, tvbuff_t *tvb, int offset, int len, case TNCOMPORT_SETPARITY: len--; if (len >= 1) { - guint8 parity = tvb_get_guint8(tvb, offset+1); + guint8 parity = tvb_get_guint8(tvb, offset+1); const char *pr = (parity > 5) ? "<invalid>" : parities[parity]; proto_tree_add_text(tree, tvb, offset, 2, "%s Parity: %s",source,pr); } else { @@ -452,7 +451,7 @@ dissect_comport_subopt(const char *optname, tvbuff_t *tvb, int offset, int len, case TNCOMPORT_SETSTOPSIZE: len--; if (len >= 1) { - guint8 stop = tvb_get_guint8(tvb, offset+1); + guint8 stop = tvb_get_guint8(tvb, offset+1); const char *st = (stop > 3) ? "<invalid>" : stops[stop]; proto_tree_add_text(tree, tvb, offset, 2, "%s Stop: %s",source,st); } else { @@ -463,7 +462,7 @@ dissect_comport_subopt(const char *optname, tvbuff_t *tvb, int offset, int len, case TNCOMPORT_SETCONTROL: len--; if (len >= 1) { - guint8 crt = tvb_get_guint8(tvb, offset+1); + guint8 crt = tvb_get_guint8(tvb, offset+1); const char *c = (crt > 19) ? "Control: <invalid>" : control[crt]; proto_tree_add_text(tree, tvb, offset, 2, "%s %s",source,c); } else { @@ -478,7 +477,7 @@ dissect_comport_subopt(const char *optname, tvbuff_t *tvb, int offset, int len, const char *print_pattern = (cmd == TNCOMPORT_SETLINESTATEMASK) ? "%s Set Linestate Mask: %s" : "%s Linestate: %s"; char ls_buffer[512]; - guint8 ls = tvb_get_guint8(tvb, offset+1); + guint8 ls = tvb_get_guint8(tvb, offset+1); int print_count = 0; int idx; ls_buffer[0] = '\0'; diff --git a/plugins/gryphon/packet-gryphon.c b/plugins/gryphon/packet-gryphon.c index e7727303e2..13bae87b1e 100644 --- a/plugins/gryphon/packet-gryphon.c +++ b/plugins/gryphon/packet-gryphon.c @@ -3,7 +3,7 @@ * By Steve Limkemann <stevelim@dgtech.com> * Copyright 1998 Steve Limkemann * - * $Id: packet-gryphon.c,v 1.36 2003/04/30 02:35:25 gerald Exp $ + * $Id: packet-gryphon.c,v 1.37 2003/06/12 08:33:32 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -1537,16 +1537,16 @@ resp_list(tvbuff_t *tvb, int offset, proto_tree *pt) return offset; } -#define GRYPHON_CMD_START_STR_LEN 120 static int cmd_start(tvbuff_t *tvb, int offset, proto_tree *pt) { - char string[GRYPHON_CMD_START_STR_LEN]; + char *string; gint length; - offset = cmd_delete(tvb, offset, pt); - length = tvb_get_nstringz0(tvb, offset, GRYPHON_CMD_START_STR_LEN, string) + 1; + offset = cmd_delete(tvb, offset, pt); /* decode the name */ + string = tvb_get_stringz(tvb, offset, &length); proto_tree_add_text(pt, tvb, offset, length, "Arguments: %s", string); + g_free(string); offset += length; length = 3 - (length + 3) % 4; if (length) { |