aboutsummaryrefslogtreecommitdiffstats
path: root/packet-smb-common.c
diff options
context:
space:
mode:
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2003-06-12 08:33:32 +0000
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2003-06-12 08:33:32 +0000
commit910425338ab45c1f5caedb182243ba5f7fd2cb19 (patch)
tree22f7363da150c57eb593a2e5871033e8b8585437 /packet-smb-common.c
parent5071071567be39aaae134fdb1e45d0e6905854ad (diff)
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. git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@7859 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'packet-smb-common.c')
-rw-r--r--packet-smb-common.c20
1 files changed, 5 insertions, 15 deletions
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;
}