diff options
author | Gerald Combs <gerald@wireshark.org> | 2018-03-08 23:50:28 +0000 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2018-03-09 00:19:22 +0000 |
commit | 6e32335be61851592d8158772b743c55ae132eb9 (patch) | |
tree | 5128945d3500fedc1db328fd001b06379de29505 /epan/maxmind_db.c | |
parent | 5f35b041c2d731297cdd4d780d029743fd49b9b4 (diff) |
Intern MaxMinDB IPv6 addresses.
Make sure our IPv6 addresses are unique and allocated, similar to
our strings.
Bug: 14514
Change-Id: I602b3b0ec4674fb2bc8cbaa973a73a6f3188e0c3
Reviewed-on: https://code.wireshark.org/review/26371
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'epan/maxmind_db.c')
-rw-r--r-- | epan/maxmind_db.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/epan/maxmind_db.c b/epan/maxmind_db.c index 6ca8ad5dc6..78973555fc 100644 --- a/epan/maxmind_db.c +++ b/epan/maxmind_db.c @@ -100,7 +100,7 @@ static void mmdb_resolve_stop(void); #define RES_LOCATION_LONGITUDE "location.longitude" #define RES_END "# End " -// Interned strings, similar to GLib's string chunks. +// Interned strings and v6 addresses, similar to GLib's string chunks. static const char *chunkify_string(char *key) { key = g_strstrip(key); char *chunk_string = (char *) wmem_map_lookup(mmdb_str_chunk, key); @@ -113,6 +113,17 @@ static const char *chunkify_string(char *key) { return chunk_string; } +static const void *chunkify_v6_addr(const ws_in6_addr *addr) { + void *chunk_v6_bytes = (char *) wmem_map_lookup(mmdb_ipv6_map, addr->bytes); + + if (!chunk_v6_bytes) { + chunk_v6_bytes = wmem_memdup(wmem_epan_scope(), addr->bytes, sizeof(struct in6_addr)); + wmem_map_insert(mmdb_ipv6_map, chunk_v6_bytes, chunk_v6_bytes); + } + + return chunk_v6_bytes; +} + static gboolean process_mmdbr_stdout(int fd) { @@ -192,7 +203,7 @@ process_mmdbr_stdout(int fd) { MMDB_DEBUG("inserting v6 %p %s: city %s country %s", (void *) mmdb_val, cur_addr, mmdb_val->city, mmdb_val->country); ws_in6_addr addr; ws_inet_pton6(cur_addr, &addr); - wmem_map_insert(mmdb_ipv6_map, addr.bytes, mmdb_val); + wmem_map_insert(mmdb_ipv6_map, chunkify_v6_addr(&addr), mmdb_val); new_entries = TRUE; } } @@ -441,7 +452,7 @@ maxmind_db_lookup_ipv6(const ws_in6_addr *addr) { } result = &mmdb_not_found; - wmem_map_insert(mmdb_ipv6_map, addr->bytes, result); + wmem_map_insert(mmdb_ipv6_map, chunkify_v6_addr(addr), result); } return result; |