diff options
author | Michael Mann <mmann78@netscape.net> | 2012-08-09 13:59:29 +0000 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2012-08-09 13:59:29 +0000 |
commit | 05a305d332472ed5871d60e5ca00b8a7e99fc060 (patch) | |
tree | b2dfdb61193c3bbb411eb4b78ce404681455816d /epan/emem.c | |
parent | 7dc5eaec0c406ab3d4bea0ec2d260d6a7d196f9d (diff) |
Make emem_tree_*32_array functions non-destructive. The following dissectors/files have affectively been bugfixed by the change:
packet-classicstun.c
packet-reload-framing.c (probably)
packet-reload.c
packet-sccp.c
packet-sua.c
packet-tcp.c
packet-xmcp.c
\epan\gcp.c
The following files unnecessarily recreate keys because of the previously destructive nature of emem_tree_*32_array functions:
packet-btl2cap.c
packet-nfs.c
packet-rpc.c
packet-scsi-osd.c
packet-stun.c (per Bug 7569)
These could be cleaned up, but it's not like the key recreation is burning CPU cycles.
svn path=/trunk/; revision=44380
Diffstat (limited to 'epan/emem.c')
-rw-r--r-- | epan/emem.c | 120 |
1 files changed, 111 insertions, 9 deletions
diff --git a/epan/emem.c b/epan/emem.c index a9e8d353ee..13a3c9fe06 100644 --- a/epan/emem.c +++ b/epan/emem.c @@ -1841,9 +1841,8 @@ create_sub_tree(void* d) /* insert a new node in the tree. if this node matches an already existing node * then just replace the data for that node */ - -void -emem_tree_insert32_array(emem_tree_t *se_tree, emem_tree_key_t *key, void *data) +static void +emem_tree_insert32_array_local(emem_tree_t *se_tree, emem_tree_key_t *key, void *data) { emem_tree_t *next_tree; @@ -1863,11 +1862,44 @@ emem_tree_insert32_array(emem_tree_t *se_tree, emem_tree_key_t *key, void *data) key[0].length--; key[0].key++; } - emem_tree_insert32_array(next_tree, key, data); + emem_tree_insert32_array_local(next_tree, key, data); } -void * -emem_tree_lookup32_array(emem_tree_t *se_tree, emem_tree_key_t *key) +void +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; + + if((key[0].length<1)||(key[0].length>100)){ + DISSECTOR_ASSERT_NOT_REACHED(); + } + + /* Make a copy of the keys so the length isn't destroyed */ + while ((local_key->key != NULL) && (local_key->length != 0)) { + key_count++; + 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; + + emem_tree_insert32_array_local(se_tree, local_key, data); +} + +static void * +emem_tree_lookup32_array_local(emem_tree_t *se_tree, emem_tree_key_t *key) { emem_tree_t *next_tree; @@ -1889,11 +1921,46 @@ emem_tree_lookup32_array(emem_tree_t *se_tree, emem_tree_key_t *key) key[0].length--; key[0].key++; } - return emem_tree_lookup32_array(next_tree, key); + return emem_tree_lookup32_array_local(next_tree, key); } void * -emem_tree_lookup32_array_le(emem_tree_t *se_tree, emem_tree_key_t *key) +emem_tree_lookup32_array(emem_tree_t *se_tree, emem_tree_key_t *key) +{ + int key_count = 0; + emem_tree_key_t *local_key = key, + *copy_key; + + if(!se_tree || !key) return NULL; /* prevent searching on NULL pointer */ + + if((key[0].length<1)||(key[0].length>100)){ + DISSECTOR_ASSERT_NOT_REACHED(); + } + + /* Make a copy of the keys so the length isn't destroyed */ + while ((local_key->key != NULL) && (local_key->length != 0)) { + key_count++; + 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; + + return emem_tree_lookup32_array_local(se_tree, local_key); +} + +static void * +emem_tree_lookup32_array_le_local(emem_tree_t *se_tree, emem_tree_key_t *key) { emem_tree_t *next_tree; @@ -1917,7 +1984,42 @@ emem_tree_lookup32_array_le(emem_tree_t *se_tree, emem_tree_key_t *key) key[0].length--; key[0].key++; } - return emem_tree_lookup32_array_le(next_tree, key); + return emem_tree_lookup32_array_le_local(next_tree, key); +} + +void * +emem_tree_lookup32_array_le(emem_tree_t *se_tree, emem_tree_key_t *key) +{ + int key_count = 0; + emem_tree_key_t *local_key = key, + *copy_key; + + if(!se_tree || !key) return NULL; /* prevent searching on NULL pointer */ + + if((key[0].length<1)||(key[0].length>100)){ + DISSECTOR_ASSERT_NOT_REACHED(); + } + + /* Make a copy of the keys so the length isn't destroyed */ + while ((local_key->key != NULL) && (local_key->length != 0)) { + key_count++; + 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; + + return emem_tree_lookup32_array_le_local(se_tree, local_key); } /* Strings are stored as an array of uint32 containing the string characters |