aboutsummaryrefslogtreecommitdiffstats
path: root/packet-smb.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2003-06-12 08:33:32 +0000
committerGuy Harris <guy@alum.mit.edu>2003-06-12 08:33:32 +0000
commitee97ce31966f61de148ad85cb229e76a88801b02 (patch)
tree22f7363da150c57eb593a2e5871033e8b8585437 /packet-smb.c
parent04a87185285865ae91f903662c4bc721f66c8d88 (diff)
downloadwireshark-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
Diffstat (limited to 'packet-smb.c')
-rw-r--r--packet-smb.c5
1 files changed, 2 insertions, 3 deletions
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);