Use "tvb_get_string()" in "proto_tree_set_string_tvb()" - it won't leak
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Thu, 20 Nov 2003 05:20:17 +0000 (05:20 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Thu, 20 Nov 2003 05:20:17 +0000 (05:20 +0000)
memory if it throws an exception, as it checks whether the entire string
is in the tvbuff *before* allocating a buffer for it, and that also
means that if the length is absurdly large, an exception will be thrown,
rather than the memory allocation failing.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@9043 f5534014-38df-0310-8fa8-9805f1628bb7

epan/proto.c

index 8e1aa05e04531763a0351ec3bbc3af5d182e8db6..d85d3c4896ef6e5a66c06d46cf5b19912799a494 100644 (file)
@@ -1,7 +1,7 @@
 /* proto.c
  * Routines for protocol tree
  *
- * $Id: proto.c,v 1.103 2003/11/16 23:17:24 guy Exp $
+ * $Id: proto.c,v 1.104 2003/11/20 05:20:17 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -1278,9 +1278,7 @@ proto_tree_set_string_tvb(field_info *fi, tvbuff_t *tvb, gint start, gint length
        }
 
        /* This memory is freed in proto_tree_free_node() */
-       string = g_malloc(length + 1);
-       tvb_memcpy(tvb, string, start, length);
-       string[length] = '\0';
+       string = tvb_get_string(tvb, start, length);
        proto_tree_set_string(fi, string, TRUE);
 }