Wireshark-dev: Re: [Wireshark-dev] [Wireshark-commits] rev 44380: /trunk/epan/ /trunk/epan/: em

Date: Thu, 9 Aug 2012 16:33:18 -0400 (EDT)
Does this patch help?  If not, I would consider blaming guids_add_guid for not initializing the key member of the emem_tree_key_t structure.  Even though I think either would be caught by the DISSECTOR_ASSERT_NOT_REACHED macro. Also, are there warning for emem_tree_lookup32_array() as well?
-----Original Message-----
From: Jeff Morriss <jeff.morriss.ws@xxxxxxxxx>
To: wireshark-dev <wireshark-dev@xxxxxxxxxxxxx>
Sent: Thu, Aug 9, 2012 4:06 pm
Subject: Re: [Wireshark-dev] [Wireshark-commits] rev 44380: /trunk/epan/ /trunk/epan/: emem.c

mmann@xxxxxxxxxxxxx wrote:
> http://anonsvn.wireshark.org/viewvc/viewvc.cgi?view=rev&revision=44380
> 
> User: mmann
> Date: 2012/08/09 06:59 AM
> 
> Log:
>  Make emem_tree_*32_array functions non-destructive.

With this change Valgrind issues many, many warnings as Wireshark starts:

==10126== Conditional jump or move depends on uninitialised value(s)
==10126==    at 0x6071DEF: emem_tree_insert32_array (emem.c:1887)
==10126==    by 0x607874E: guids_add_guid (guid-utils.c:117)
==10126==    by 0x62638CE: dcerpc_init_uuid (packet-dcerpc.c:830)
==10126==    by 0x69E3061: register_all_protocol_handoffs (register.c:1360)
==10126==    by 0x6085CA2: proto_init (proto.c:401)
==10126==    by 0x6073565: epan_init (epan.c:113)
==10126==    by 0x418AE5: main (tshark.c:963)
==10126==
==10126== More than 100 errors detected.  Subsequent errors
==10126== will still be recorded, but in less detail than before.

___________________________________________________________________________
Sent via:    Wireshark-dev mailing list <wireshark-dev@xxxxxxxxxxxxx>
Archives:    http://www.wireshark.org/lists/wireshark-dev
Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev
             mailto:wireshark-dev-request@xxxxxxxxxxxxx?subject=unsubscribe
Index: epan/emem.c
===================================================================
--- epan/emem.c	(revision 44392)
+++ epan/emem.c	(working copy)
@@ -1869,8 +1869,7 @@
 emem_tree_insert32_array(emem_tree_t *se_tree, emem_tree_key_t *key, void *data)
 {
 	int key_count = 0;
-	emem_tree_key_t *local_key = key,
-					*copy_key;
+	emem_tree_key_t *local_key = key;
 
 	if((key[0].length<1)||(key[0].length>100)){
 		DISSECTOR_ASSERT_NOT_REACHED();
@@ -1882,19 +1881,7 @@
 		local_key++;
 	}
 
-	copy_key = ep_alloc(sizeof(emem_tree_key_t)*(key_count+1));
-	local_key = copy_key;
-	while ((key->key != NULL) && (key->length != 0)) {
-		copy_key->length = key->length;
-		copy_key->key = key->key;
-		key++;
-		copy_key++;
-	}
-
-	/* "NULL terminate" the key */
-	copy_key->length = 0;
-	copy_key->key = NULL;
-
+	local_key = ep_memdup(key, sizeof(emem_tree_key_t)*(key_count+1));
 	emem_tree_insert32_array_local(se_tree, local_key, data);
 }