aboutsummaryrefslogtreecommitdiffstats
path: root/packet-enip.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2004-02-25 09:31:07 +0000
committerGuy Harris <guy@alum.mit.edu>2004-02-25 09:31:07 +0000
commit857318d3b760aa1ee27b9025746e1f39ce946a53 (patch)
tree4e9d5900443b375741a9966dee096dee52c01a1c /packet-enip.c
parent3353ca1d5a8307ce1ae6afd49b3f7525596e0910 (diff)
Use "tvb_get_string()" instead of allocating a (len+1)-sized buffer,
"tvb_memcpy()"ing to it, and putting in a null terminator; "tvb_get_string()" will check whether all bytes of the string are present before allocating the buffer, so that you don't leak memory if the copy throws an exception, and don't crash if the length is absurdly large. Use "tvb_memdup()" instead of allocating a buffer and "tvb_memcpy()"ing to it, so that an exception is thrown before you try to allocate the buffer (for the same reasons as listed above). Before allocating a buffer used when processing a chunk of data from a packet, get a pointer to the chunk with "tvb_get_ptr()", or check that the data is all there with "tvb_ensure_bytes_exist()", so that an exception is thrown before you try to allocate the buffer (for the same reasons as listed above). Fix up the lengths of the tvbuff used when dissecting ONC RPC opaque data with a particular dissector. svn path=/trunk/; revision=10236
Diffstat (limited to 'packet-enip.c')
-rw-r--r--packet-enip.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/packet-enip.c b/packet-enip.c
index 2fe5f7a9b6..464c7080db 100644
--- a/packet-enip.c
+++ b/packet-enip.c
@@ -6,7 +6,7 @@
* Magnus Hansson <mah@hms.se>
* Joakim Wiberg <jow@hms.se>
*
- * $Id: packet-enip.c,v 1.9 2004/02/04 20:34:53 guy Exp $
+ * $Id: packet-enip.c,v 1.10 2004/02/25 09:31:05 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -661,10 +661,11 @@ static const value_string enip_class_names_vals[] = {
static proto_item*
add_byte_array_text_to_proto_tree( proto_tree *tree, tvbuff_t *tvb, gint start, gint length, const char* str )
{
- char *tmp, *tmp2, *tmp2start;
- proto_item* pi;
- int i,tmp_length;
- guint32 octet;
+ const char *tmp;
+ char *tmp2, *tmp2start;
+ proto_item *pi;
+ int i,tmp_length,tmp2_length;
+ guint32 octet;
/* At least one version of Apple's C compiler/linker is buggy, causing
a complaint from the linker about the "literal C string section"
not ending with '\0' if we initialize a 16-element "char" array with
@@ -676,22 +677,21 @@ add_byte_array_text_to_proto_tree( proto_tree *tree, tvbuff_t *tvb, gint start,
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
-
if( ( length * 2 ) > 32 )
{
- tmp2 = (char*)g_malloc( 36 );
tmp_length = 16;
+ tmp2_length = 36;
}
else
{
- tmp2 = (char*)g_malloc( ( length * 2 ) + 1 );
tmp_length = length;
+ tmp2_length = ( length * 2 ) + 1;
}
- tmp2start = tmp2;
+ tmp = tvb_get_ptr( tvb, start, tmp_length );
+ tmp2 = (char*)g_malloc( tmp2_length );
- tmp = (char*)g_malloc( tmp_length );
- tvb_memcpy( tvb, tmp, start, tmp_length );
+ tmp2start = tmp2;
for( i = 0; i < tmp_length; i++ )
{
@@ -713,7 +713,6 @@ add_byte_array_text_to_proto_tree( proto_tree *tree, tvbuff_t *tvb, gint start,
pi = proto_tree_add_text( tree, tvb, start, length, "%s%s", str, tmp2start );
- g_free( tmp );
g_free( tmp2start );
return( pi );