Don't do unsafe pointer casting

Don't cast a pointer-to-int into a pointer-to-pointer and pass the
resulting pointer to g_hash_table_lookup_extended() - pointers and ints
are *not* guaranteed to be the same size.  Instead, just have a variable
of type gpointer, pass a pointer to *that*, and then run that result
through GPOINTER_TO_UINT().

This fixes a reproducible crash.

Change-Id: I42954f222ab59866cb909b80d9dbb1d2668d2aff
Reviewed-on: https://code.wireshark.org/review/5457
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2014-11-23 17:03:42 -08:00
parent ec650d45a9
commit eb93f3bdfb
1 changed files with 6 additions and 4 deletions

View File

@ -621,14 +621,15 @@ add_conversation_table_data_with_conv_id(
} else {
/* try to find it among the existing known conversations */
conv_key_t existing_key;
gpointer conversation_idx_hash_val;
existing_key.addr1 = *addr1;
existing_key.addr2 = *addr2;
existing_key.port1 = port1;
existing_key.port2 = port2;
existing_key.conv_id = conv_id;
if (g_hash_table_lookup_extended(ch->hashtable, &existing_key, NULL, (gpointer *) &conversation_idx)) {
conv_item = &g_array_index(ch->conv_array, conv_item_t, conversation_idx);
if (g_hash_table_lookup_extended(ch->hashtable, &existing_key, NULL, &conversation_idx_hash_val)) {
conv_item = &g_array_index(ch->conv_array, conv_item_t, GPOINTER_TO_UINT(conversation_idx_hash_val));
}
}
@ -748,12 +749,13 @@ add_hostlist_table_data(conv_hash_t *ch, const address *addr, guint32 port, gboo
else {
/* try to find it among the existing known conversations */
host_key_t existing_key;
gpointer talker_idx_hash_val;
existing_key.myaddress = *addr;
existing_key.port = port;
if (g_hash_table_lookup_extended(ch->hashtable, &existing_key, NULL, (gpointer *) &talker_idx)) {
talker = &g_array_index(ch->conv_array, hostlist_talker_t, talker_idx);
if (g_hash_table_lookup_extended(ch->hashtable, &existing_key, NULL, &talker_idx_hash_val)) {
talker = &g_array_index(ch->conv_array, hostlist_talker_t, GPOINTER_TO_UINT(talker_idx_hash_val));
}
}