diff options
author | Luis Ontanon <luis.ontanon@gmail.com> | 2006-03-10 22:01:10 +0000 |
---|---|---|
committer | Luis Ontanon <luis.ontanon@gmail.com> | 2006-03-10 22:01:10 +0000 |
commit | 4e1ca8f2c3892d6cb949344b20a3e84e021c7ec2 (patch) | |
tree | 634ebb44840e760472b7c6bf7639f81614ca41c7 /asn1/h248 | |
parent | 8b22411809445d94ce0ff9bf2b78c52c046d62f1 (diff) |
fix coverity CIDs 113 and 114.
while at it change the h248 context analysis to use se_trees instead of GHashTables
svn path=/trunk/; revision=17571
Diffstat (limited to 'asn1/h248')
-rw-r--r-- | asn1/h248/h248.cnf | 30 | ||||
-rw-r--r-- | asn1/h248/packet-h248-template.c | 171 | ||||
-rw-r--r-- | asn1/h248/packet-h248-template.h | 10 |
3 files changed, 122 insertions, 89 deletions
diff --git a/asn1/h248/h248.cnf b/asn1/h248/h248.cnf index bd561c7d9a..a6aee5dd28 100644 --- a/asn1/h248/h248.cnf +++ b/asn1/h248/h248.cnf @@ -268,18 +268,24 @@ ServiceChangeReply/terminationID terminationIDList tvbuff_t* new_tvb; offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index, &new_tvb); - term->len = tvb_length(new_tvb); - term->type = 0; /* unknown */ - - if (term->len) { - term->buffer = ep_tvb_memdup(new_tvb,0,term->len); - term->str = bytes_to_str(term->buffer,term->len); - } - - term = h248_cmd_add_term(msg, trx, cmd, term, wild_term); - - if (new_tvb && h248_term_handle) { - call_dissector(h248_term_handle, new_tvb, pinfo, tree); + if (new_tvb) { + term->len = tvb_length(new_tvb); + term->type = 0; /* unknown */ + + if (term->len) { + term->buffer = ep_tvb_memdup(new_tvb,0,term->len); + term->str = bytes_to_str(term->buffer,term->len); + } + + term = h248_cmd_add_term(msg, trx, cmd, term, wild_term); + + if (h248_term_handle) { + call_dissector(h248_term_handle, new_tvb, pinfo, tree); + } + } else { + term->len = 0; + term->buffer = (guint8*)ep_strdup(""); + term->str = ep_strdup("?"); } #.END diff --git a/asn1/h248/packet-h248-template.c b/asn1/h248/packet-h248-template.c index fb8be85c2f..a3ec2e8297 100644 --- a/asn1/h248/packet-h248-template.c +++ b/asn1/h248/packet-h248-template.c @@ -47,6 +47,7 @@ #include <epan/dissectors/packet-isup.h> #include <epan/dissectors/packet-q931.h> #include <epan/dissectors/packet-alcap.h> +#include <epan/dissectors/packet-mtp3.h> #include <epan/sctpppids.h> #define PNAME "H.248 MEGACO" @@ -149,10 +150,10 @@ static GHashTable* h248_wild_terms = NULL; static dissector_table_t h248_package_bin_dissector_table=NULL; #endif -static GHashTable* msgs = NULL; -static GHashTable* trxs = NULL; -static GHashTable* ctxs_by_trx = NULL; -static GHashTable* ctxs = NULL; +static se_tree_t* msgs = NULL; +static se_tree_t* trxs = NULL; +static se_tree_t* ctxs_by_trx = NULL; +static se_tree_t* ctxs = NULL; static gboolean h248_prefs_initialized = FALSE; static gboolean keep_persistent_data = FALSE; @@ -1138,22 +1139,28 @@ dissect_h248_MtpAddress(gboolean implicit_tag, tvbuff_t *tvb, int offset, packet -static h248_msg_t* h248_msg(packet_info* pinfo, int offset) { +static h248_msg_t* h248_msg(packet_info* pinfo, int o) { h248_msg_t* m; - guint framenum = pinfo->fd->num; - + guint32 framenum = (guint32)pinfo->fd->num; + guint32 offset = (guint32)o; + if (keep_persistent_data) { - gchar* key = ep_strdup_printf("%u-%i",framenum,offset); + se_tree_key_t key[] = { + {1,&(framenum)}, + {1,&offset}, + {0,NULL}, + }; - if (( m = g_hash_table_lookup(msgs,key) )) { + if (( m = se_tree_lookup32_array(msgs,key) )) { m->commited = TRUE; + return m; } else { m = se_alloc(sizeof(h248_msg_t)); m->framenum = framenum; m->trxs = NULL; m->commited = FALSE; - g_hash_table_insert(msgs,se_strdup(key),m); + se_tree_insert32_array(msgs,key,m); } } else { m = ep_new0(h248_msg_t); @@ -1162,25 +1169,39 @@ static h248_msg_t* h248_msg(packet_info* pinfo, int offset) { m->commited = FALSE; } - if (pinfo->net_src.type == AT_NONE) { - m->addr_label = ""; - } else { - address* src = &(pinfo->net_src); - address* dst = &(pinfo->net_dst); - address* lo_addr; - address* hi_addr; - - if (CMP_ADDRESS(src, dst) < 0) { - lo_addr = src; - hi_addr = dst; - } else { - lo_addr = dst; - hi_addr = src; - } - - m->addr_label = ep_strdup_printf("%s<->%s",address_to_str(lo_addr),address_to_str(hi_addr)); - } - + address* src = &(pinfo->src); + address* dst = &(pinfo->dst); + address* lo_addr; + address* hi_addr; + + if (CMP_ADDRESS(src, dst) < 0) { + lo_addr = src; + hi_addr = dst; + } else { + lo_addr = dst; + hi_addr = src; + } + + switch(lo_addr->type) { + case AT_NONE: + m->lo_addr = 0; + m->hi_addr = 0; + break; + case AT_IPv4: + memcpy((guint8*)m->hi_addr,hi_addr->data,4); + memcpy((guint8*)m->lo_addr,lo_addr->data,4); + break; + case AT_SS7PC: + m->hi_addr = mtp3_pc_hash(hi_addr->data); + m->lo_addr = mtp3_pc_hash(lo_addr->data); + break; + default: + /* XXX: heuristic and error prone */ + m->hi_addr = g_str_hash(address_to_str(hi_addr)); + m->lo_addr = g_str_hash(address_to_str(lo_addr)); + break; + } + return m; } @@ -1202,20 +1223,26 @@ static h248_trx_t* h248_trx(h248_msg_t* m ,guint32 t_id , h248_trx_type_t type) DISSECTOR_ASSERT(! "a trx that should exist does not!" ); } else { - gchar* key = ep_strdup_printf("T%s:%.8x",m->addr_label,t_id); + se_tree_key_t key[] = { + {1,&(m->hi_addr)}, + {1,&(m->lo_addr)}, + {1,&(t_id)}, + {0,NULL} + }; + trxmsg = se_alloc(sizeof(h248_trx_msg_t)); - t = g_hash_table_lookup(trxs,key); + t = se_tree_lookup32_array(trxs,key); if (!t) { t = se_alloc(sizeof(h248_trx_t)); - t->key = se_strdup(key); + t->initial = m; t->id = t_id; t->type = type; t->pendings = 0; t->error = 0; t->cmds = NULL; - g_hash_table_insert(trxs,t->key,t); + se_tree_insert32_array(trxs,key,t); } /* XXX: request, reply and ack + point to frames where they are */ @@ -1231,7 +1258,7 @@ static h248_trx_t* h248_trx(h248_msg_t* m ,guint32 t_id , h248_trx_type_t type) } else { t = ep_new(h248_trx_t); trxmsg = ep_new(h248_trx_msg_t); - t->key = NULL; + t->initial = NULL; t->id = t_id; t->type = type; t->pendings = 0; @@ -1256,20 +1283,32 @@ static h248_trx_t* h248_trx(h248_msg_t* m ,guint32 t_id , h248_trx_type_t type) static h248_ctx_t* h248_ctx(h248_msg_t* m, h248_trx_t* t, guint32 c_id) { h248_ctx_t* context = NULL; h248_ctx_t** context_p = NULL; - + if ( !m || !t ) return NULL; if (keep_persistent_data) { + se_tree_key_t ctx_key[] = { + {1,&(m->hi_addr)}, + {1,&(m->lo_addr)}, + {1,&(c_id)}, + {0,NULL} + }; + + se_tree_key_t trx_key[] = { + {1,&(m->hi_addr)}, + {1,&(m->lo_addr)}, + {1,&(t->id)}, + {0,NULL} + }; + if (m->commited) { - gchar* key = ep_strdup_printf("%s:%.8x",m->addr_label,c_id); - - if (( context = g_hash_table_lookup(ctxs_by_trx,t->key) )) { + if (( context = se_tree_lookup32_array(ctxs_by_trx,trx_key) )) { return context; - } if ((context_p = g_hash_table_lookup(ctxs,key))) { + } if ((context_p = se_tree_lookup32_array(ctxs,ctx_key))) { context = *context_p; do { - if (context->first_frame <= m->framenum) { + if (context->initial->framenum <= m->framenum) { return context; } } while(( context = context->prev )); @@ -1278,29 +1317,24 @@ static h248_ctx_t* h248_ctx(h248_msg_t* m, h248_trx_t* t, guint32 c_id) { } } else { if (c_id == CHOOSE_CONTEXT) { - if (! ( context = g_hash_table_lookup(ctxs_by_trx,t->key))) { + if (! ( context = se_tree_lookup32_array(ctxs_by_trx,trx_key))) { context = se_alloc(sizeof(h248_ctx_t)); - context->key = NULL; + context->initial = m; context->cmds = NULL; context->id = c_id; - context->first_frame = m->framenum; context->terms.last = &(context->terms); context->terms.next = NULL; context->terms.term = NULL; - g_hash_table_insert(ctxs_by_trx,t->key,context); + se_tree_insert32_array(ctxs_by_trx,trx_key,context); } } else { - gchar* key = ep_strdup_printf("C%s:%.8x",m->addr_label,c_id); - - - if (( context = g_hash_table_lookup(ctxs_by_trx,t->key) )) { - if (( context_p = g_hash_table_lookup(ctxs,key) )) { + if (( context = se_tree_lookup32_array(ctxs_by_trx,trx_key) )) { + if (( context_p = se_tree_lookup32_array(ctxs,ctx_key) )) { if (context != *context_p) { context = se_alloc(sizeof(h248_ctx_t)); - context->key = se_strdup(key); + context->initial = m; context->id = c_id; - context->first_frame = m->framenum; context->cmds = NULL; context->terms.last = &(context->terms); context->terms.next = NULL; @@ -1312,23 +1346,22 @@ static h248_ctx_t* h248_ctx(h248_msg_t* m, h248_trx_t* t, guint32 c_id) { } else { context_p = se_alloc(sizeof(void*)); *context_p = context; - context->key = se_strdup(key); + context->initial = m; context->id = c_id; - g_hash_table_insert(ctxs,context->key,context_p); + se_tree_insert32_array(ctxs,ctx_key,context_p); } - } else if (! ( context_p = g_hash_table_lookup(ctxs,key) )) { + } else if (! ( context_p = se_tree_lookup32_array(ctxs,ctx_key) )) { context = se_alloc(sizeof(h248_ctx_t)); - context->key = se_strdup(key); + context->initial = m; context->id = c_id; context->cmds = NULL; - context->first_frame = m->framenum; context->terms.last = &(context->terms); context->terms.next = NULL; context->terms.term = NULL; context_p = se_alloc(sizeof(void*)); *context_p = context; - g_hash_table_insert(ctxs,context->key,context_p); + se_tree_insert32_array(ctxs,ctx_key,context_p); } else { context = *context_p; } @@ -1336,7 +1369,7 @@ static h248_ctx_t* h248_ctx(h248_msg_t* m, h248_trx_t* t, guint32 c_id) { } } else { context = ep_new(h248_ctx_t); - context->key = NULL; + context->initial = m; context->cmds = NULL; context->id = c_id; context->terms.last = &(context->terms); @@ -1626,11 +1659,12 @@ static gchar* h248_cmd_to_str(h248_cmd_t* c) { } static gchar* h248_trx_to_str(h248_msg_t* m, h248_trx_t* t) { - gchar* s = ep_strdup_printf("T %x { ",t->id); + gchar* s; h248_cmd_msg_t* c; if ( !m || !t ) return "-"; - + + s = ep_strdup_printf("T %x { ",t->id); if (t->cmds) { if (t->cmds->cmd->ctx) { @@ -1809,18 +1843,6 @@ dissect_h248(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) static void h248_init(void) { - if (msgs) g_hash_table_destroy(msgs); - msgs = g_hash_table_new(g_str_hash,g_str_equal); - - if (trxs) g_hash_table_destroy(trxs); - trxs = g_hash_table_new(g_str_hash,g_str_equal); - - if (ctxs_by_trx) g_hash_table_destroy(ctxs_by_trx); - ctxs_by_trx = g_hash_table_new(g_str_hash,g_str_equal); - - if (ctxs) g_hash_table_destroy(ctxs); - ctxs = g_hash_table_new(g_str_hash,g_str_equal); - if (!h248_prefs_initialized) { h248_prefs_initialized = TRUE; } else { @@ -2094,6 +2116,11 @@ void proto_register_h248(void) { register_init_routine( &h248_init ); + msgs = se_tree_create(SE_TREE_TYPE_RED_BLACK); + trxs = se_tree_create(SE_TREE_TYPE_RED_BLACK); + ctxs_by_trx = se_tree_create(SE_TREE_TYPE_RED_BLACK); + ctxs = se_tree_create(SE_TREE_TYPE_RED_BLACK); + } /*--- proto_reg_handoff_h248 -------------------------------------------*/ diff --git a/asn1/h248/packet-h248-template.h b/asn1/h248/packet-h248-template.h index 6b7be569be..5f85132f24 100644 --- a/asn1/h248/packet-h248-template.h +++ b/asn1/h248/packet-h248-template.h @@ -64,8 +64,9 @@ typedef enum { typedef struct _h248_msg_t { - gchar* addr_label; - guint framenum; + guint32 lo_addr; + guint32 hi_addr; + guint32 framenum; struct _h248_trx_msg_t* trxs; gboolean commited; } h248_msg_t; @@ -83,7 +84,7 @@ typedef struct _h248_cmd_msg_t { } h248_cmd_msg_t; typedef struct _h248_trx_t { - gchar* key; + h248_msg_t* initial; guint32 id; h248_trx_type_t type; guint pendings; @@ -147,9 +148,8 @@ typedef struct _h248_cmd_t { typedef struct _h248_ctx_t { - gchar* key; + h248_msg_t* initial; guint32 id; - guint first_frame; struct _h248_cmd_msg_t* cmds; struct _h248_ctx_t* prev; h248_terms_t terms; |