Commit Graph

38 Commits

Author SHA1 Message Date
João Valverde 133b0c583f Move epan/wmem/wmem_scopes.h to epan/
This header was installed incorrectly to epan/wmem_scopes.h.

Instead of creating additional installation rules for a single
header in a subfolder (kept for backward compatibility) just
rename the standard "epan/wmem/wmem.h" include to
"epan/wmem_scopes.h" and fix the documentation.

Now the header is installed *correctly* to epan/wmem_scopes.h.
2021-07-26 14:56:11 +00:00
João Valverde 39df3ae3c0 Replace g_log() calls with ws_log() 2021-06-16 12:50:27 +00:00
Vasil Velichkov b9e942930f maxmin_db: Fix a memory leak in maxmind_db_pop_response
The mmdb_val needs to be allocated with the same wmem allocator as the
one used for mmdb_ipv4_map and mmdb_ipv6_map hash maps.

Build with ENABLE_ASAN and run `ctest -R suite_fileformats -V`

24: Direct leak of 144 byte(s) in 2 object(s) allocated from:
24:     #0 0x55e6deb6eebf in malloc (/home/vasko/sources/wireshark/build_clang/run/tshark+0x1f1ebf)
24:     #1 0x7f708f717bb8 in g_malloc (/lib64/libglib-2.0.so.0+0x5bbb8)
24:     #2 0x7f709c0a7b3c in maxmind_db_pop_response /home/vasko/sources/wireshark/epan/maxmind_db.c:622:49
24:     #3 0x7f709c0a895f in maxmind_db_await_response /home/vasko/sources/wireshark/epan/maxmind_db.c:661:9
24:     #4 0x7f709c0a895f in maxmind_db_lookup_ipv4 /home/vasko/sources/wireshark/epan/maxmind_db.c:696:17
24:     #5 0x7f709d1a97c5 in add_geoip_info_entry /home/vasko/sources/wireshark/epan/dissectors/packet-ip.c:570:33
24:     #6 0x7f709d1a2907 in add_geoip_info /home/vasko/sources/wireshark/epan/dissectors/packet-ip.c:662:3
24:     #7 0x7f709d1a2907 in dissect_ip_v4 /home/vasko/sources/wireshark/epan/dissectors/packet-ip.c:2205:7

Fixes: v2.9.0rc0-2687-g1bab83de53 ("maxmind: Move response processing to a thread.")
2021-05-12 11:58:13 +00:00
Guy Harris 57a1514ac7 Cast away the return value of g_strlcpy() and g_strlcat().
Most of the time, the return value tells us nothing useful, as we've
already decided that we're perfectly willing to live with string
truncation.  Hopefully this keeps Coverity from whining that those
routines could return an error code (NARRATOR: They don't) and thus that
we're ignoring the possibility of failure (as indicated, we've already
decided that we can live with string truncation, so truncation is *NOT*
a failure).
2021-04-30 03:19:19 -07:00
David Perry c0abaa06f7 maxmind: add optional synchronous lookups
When tshark enables synchronous resolution of IP addresses to names,
forces calls to maxmind_db_lookup_ipv4()/_ipv6() to block-wait for the
maxmind response.

Proposed fix for #14691.
2021-04-02 06:48:42 +00:00
Dario Lombardo ea929d6401 wsutils: add local implementation of g_memdup2.
g_memdup() was deprecated and replaced with g_memdup2() in GLib 2.68,
we provide our own copy of g_memdup2() for older GLib versions.
2021-03-25 09:38:10 +00:00
Guy Harris 245086eb83 HTTPS In Still More Places, update more URLs.
Microsoft reshuffled their documentation - almost all of it moved from
msdn.microsoft.com to docs.microsoft.com.  Some blogs moved to
devblogs.microsoft.com; the comments *didn't* move, so in one case we go
to the Wayback Machine - the link isn't dead, but it formats horribly,
at least on my browser, but the archived version formats OK.

Use the Wayback Machine for some URLs, and update others.

Update the sections for MS-ADTS.

Point to the HTML versions of some RFCs and I-Ds.

Change-Id: I344b20f880de63f1ae2a4e3f9ff98af78a7fe139
Reviewed-on: https://code.wireshark.org/review/34101
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-07-27 22:56:35 +00:00
Gerald Combs 69460d44ea maxmind_db: Work around an apparent GLib bug.
g_async_queue_timeout_pop can return immediately on macOS and possibly
other OSes when using older versions of GLib. Replace it with
g_async_queue_pop and a "stop" sentinel value.

Bug: 15545
Change-Id: Id0bfacd4a94ec9645d2d27ba92d3a2f48e7d5f37
Reviewed-on: https://code.wireshark.org/review/32289
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2019-03-04 18:35:41 +00:00
Peter Wu ba1ef0ec3d Re-implement "Map" feature for Endpoints
This feature was removed in v2.5.1rc0-427-gf529ab5d0a, anticipating that
MaxMind would remove support for it in 2019. They have however changed
their mind and maintained latitude and longitude information.

They recommend displaying an accuracy radius, but the reported values
are 50, 100, 200 and 1000km. When implemented literally, a marker in
Ireland would cover the whole island plus mainland, so I have instead
opted to use a fixed radius of 1km at deeper zoom levels.

The old ipmap.html file was outdated and had broken tiles, I rewrote a
new one from scratch using the light-weight Leaflet library combined
with tiles from OpenStreetMap. This is more mobile-friendly and secure
(https, SRI). To improve handling of nearby or overlapping nodes,
clustering is used (individual nodes can still be inspected).

Browser compatibility results: IE8 is unusable, IE9 partially works
(tooltips sometimes disappear and the cluster radius control is gone),
IE11 works. Of course Firefox 65 and Chromium 72 have no issues.

The map popup description in the generated GeoJSON structure is now
split in several properties, allowing presentation to be handled by the
HTML page instead of the C code.

Bug: 14693
Change-Id: If2ec9c518f7723ac0ab27b6272463356875a0ff2
Reviewed-on: https://code.wireshark.org/review/31952
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-02-16 21:11:12 +00:00
Peter Wu 5c4458345c Change maxmind_db_lookup_ipv4 to look more like maxmind_db_lookup_ipv6
Both functions accept an address in network byte order, but
maxmind_db_lookup_ipv4 does not accept a pointer. Add an indirection and
remove unnecessary memcpy calls. This removes some confusion for me.

Change-Id: I291c54c8c55bc8048ca011b84918c8a5d3ed1398
Reviewed-on: https://code.wireshark.org/review/31951
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-02-11 05:13:37 +00:00
Peter Wu 426107f2b5 maxmind_db: improve debug messages, harden against bad input
Ensure that country, city, etc. are reset when processing new responses.
Otherwise if the new response lacks a City, then it would use the result
of the last query. Harden against bad addresses and print debug messages
if a bad address is detected.

Miscellaneous cleanups: improve debug messages (strip whitespace
earlier, etc.), use g_string_assign when possible.

Change-Id: I2acad5fcc02c5a8bf684e8fb01ee2d688d926990
Reviewed-on: https://code.wireshark.org/review/31950
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-02-11 05:12:19 +00:00
Peter Wu 43692360c4 maxmind_db: fix broken GeoIP lookups due to bad address processing
The "current address" must remain valid until the end of response is
processed, otherwise a bogus entry will be inserted. Move "cur_addr"
outside the block to avoid undefined behavior.

Change-Id: Icc2c64280ffeabd632b51d36d6be2020eb83a6a9
Fixes: v2.9.1rc0-125-g2d9a6c2583 ("maxmind_db: force buffer contain an empty string (CID: 1441961).")
Reviewed-on: https://code.wireshark.org/review/31949
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-02-11 05:10:41 +00:00
Gerald Combs f100f7f122 maxmind_db: Close our pipe FDs inside a lock.
Lock our pipe mutex before closing its file descriptors. This should
hopefully fix some infrequent crashes that I'm seeing on my Windows 7 VM.

Add a note about GRWLock behavior on Windows which doesn't appear to be
related to this issue, but which is nevertheless important.

Ping-Bug: 14701
Change-Id: I32e66a24258264fa65a907f319755594f90c0177
Reviewed-on: https://code.wireshark.org/review/31375
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-01-05 06:46:20 +00:00
Dario Lombardo 2d9a6c2583 maxmind_db: force buffer contain an empty string (CID: 1441961).
Change-Id: Ia290f528befa0c071de9e62ea264fdda0740d6f8
Reviewed-on: https://code.wireshark.org/review/31206
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2018-12-26 00:56:34 +00:00
Gerald Combs c9eab8203f maxminddb: Expand a comment.
Change-Id: Iac0d158ccc56c40c87ccc8399a8a5b16af768e12
Reviewed-on: https://code.wireshark.org/review/30901
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2018-12-03 18:44:06 +00:00
Gerald Combs 46ee43aae2 Revert "maxmind: Simplify our read logic."
This reverts commit 4154e35cde.

Apparently we do need to call PeekNamedPipe on Windows.

Change-Id: I9c9bbcb56bf1e1c2e6ae240ac5056b8a80674f15
Reviewed-on: https://code.wireshark.org/review/30900
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2018-12-03 17:08:39 +00:00
Gerald Combs 4154e35cde maxmind: Simplify our read logic.
Don't bother checking to see if our pipe has data.

Change-Id: I55f24850a16f66be9c679ad51e35df9f35c206db
Reviewed-on: https://code.wireshark.org/review/30877
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-12-02 07:51:54 +00:00
Gerald Combs ee92fcf4b4 maxmind: Process responses one character at a time.
Process mmdbresolve output one character at a time and only after
ws_pipe_data_available tells us that we can do so without blocking.

Bug: 14701
Change-Id: Ib8f5eabed28e9385585a022d948b83f830c6358c
Reviewed-on: https://code.wireshark.org/review/30850
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-12-01 09:08:21 +00:00
Gerald Combs 1bab83de53 maxmind: Move response processing to a thread.
Move response processing to a thread. Blind attempt at fixing bug 14701.

Bug: 14701
Change-Id: I2b7e6a0669c4784c7c169e659fa37ea2e62c96a3
Reviewed-on: https://code.wireshark.org/review/30837
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-11-30 06:11:59 +00:00
Pascal Quantin bcaf997f8a wsutil: introduce ws_pipe_close() helper and use it to terminate mmdbresolve
We were not calling TerminateProcess() to stop mmdbresolve.Exe process on
Windows.

Bug: 15248
Change-Id: Ic90cf438a8003a6fefb023b7056984681ce09b46
Reviewed-on: https://code.wireshark.org/review/30449
Petri-Dish: Pascal Quantin <pascal.quantin@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-11-01 06:26:13 +00:00
Pascal Quantin 54b58c5320 mmdb: do not lock the pipe mutex recursively
According to GLib documentation, take twice the lock in the same thread
leads to undefined behavior (and could lead to deadlocks).

Change-Id: I40e02ba9d619eb1db2a04f2be54c461c817b15ff
Reviewed-on: https://code.wireshark.org/review/30446
Petri-Dish: Pascal Quantin <pascal.quantin@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-11-01 06:26:00 +00:00
Pascal Quantin 852037fa3c maxmind_db.c: fix a memory leak
Change-Id: Iee898541ec723cec209a3561899530a8dbe6e680
Reviewed-on: https://code.wireshark.org/review/27809
Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
Petri-Dish: Pascal Quantin <pascal.quantin@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-05-26 05:55:56 +00:00
Gerald Combs c159d48420 maxmind: Move request processing to a thread.
It's possible to block while we're writing to our mmdbresolve pipe,
particularly on Windows. Move the write to a separate thread.

Add an #ifdef to mmdbresolve.c which helps test blocking.

Bug: 14701
Change-Id: I6cb8a46a190a268da64f1e6f54d1052d03743c95
Reviewed-on: https://code.wireshark.org/review/27750
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-05-24 04:07:44 +00:00
Gerald Combs 5fb3385701 maxmind: Process our requests more often.
The answer to

// XXX Should we call maxmind_db_lookup_process first?

in maxmind_db.c is "yes", since it's possible to fill up our pipe
between host name lookup intervals, at least on Windows. Note that we
might want to move request processing to a thread.

Bug: 14701
Change-Id: I8cfb77444d7f999e77571bc6bb61ea7f1f677778
Reviewed-on: https://code.wireshark.org/review/27644
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2018-05-18 20:10:38 +00:00
Gerald Combs 2a227f72bf Properly initialize mmdb_lookup_t.
Set our initial geographic coordinates to DBL_MAX, otherwise we might
give people the wrong impression about the PIRATA weather buoy at 0°0'0"
N 0°0'0" E.

Change-Id: I34683883ef02c4fe40d5d93a7695d0cca277345c
Reviewed-on: https://code.wireshark.org/review/26463
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2018-03-13 21:14:46 +00:00
Dario Lombardo 3ceff67514 maxmind: check val_start before using it.
Change-Id: Id3ee8e8d4c54c02d68048ec677fdda599b329713
Reviewed-on: https://code.wireshark.org/review/26417
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2018-03-11 02:11:55 +00:00
Dario Lombardo 2a9097046e maxmind: use ws_strtou32 to convert AS numbers.
Change-Id: I0578f8a674feee6e4763d5481a2285b7b2a054dc
Reviewed-on: https://code.wireshark.org/review/26416
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2018-03-11 02:08:28 +00:00
Gerald Combs 6a819d9950 MaxMindDB: Add country ISO codes.
Add and dissect country ISO codes. Prefer them when printing summary
information.

Change-Id: I3ce2bde88fa5ca2604c8bb745c42f239660252ff
Reviewed-on: https://code.wireshark.org/review/26415
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2018-03-10 19:21:42 +00:00
Gerald Combs 5564c222e2 MaxMind DB: Fixup IPv6 address interning.
Intern IPv6 addresses into their own hash table.

Change-Id: I1ad60bf56585fcd89964e949e8754af3c7512a75
Reviewed-on: https://code.wireshark.org/review/26414
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2018-03-10 17:50:33 +00:00
Gerald Combs aae6b8442c Process MaxMind DB data one line at a time.
Use fgets instead of ws_read + g_strsplit.

Change-Id: I9d13183cc129e0c749742779f9c48fdfba21a8fc
Reviewed-on: https://code.wireshark.org/review/26374
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2018-03-10 16:46:09 +00:00
Pascal Quantin c2639090de maxminf_db.c: ad an explicit cast to please gcc 7.3.1
Change-Id: Ie97008ece77e485948a3a8d418a49b77c1a52a33
Reviewed-on: https://code.wireshark.org/review/26395
Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
2018-03-09 16:40:34 +00:00
Peter Wu a395a8b993 GeoIP: avoid closing random file descriptors
Previously there were three different pipe validity checks:
PID != WS_INVALID_PID, PID != 0 and stdin != 0. This resulted in
using/closing file descriptors which might be owned by something else.

When no GeoIP databases are defined, mmdb_resolve_stop would be called
to close the pipe and set PID to WS_INVALID_PID. stdin is however not
cleared and future invocations would try to close the previous fd.

Change-Id: I1d15da29208efb41098ee6a4edeeabf61f84c2b3
Fixes: v2.5.1rc0-466-ga1da75c554 ("Transition from GeoIP Legacy to MaxMindDB.")
Reviewed-on: https://code.wireshark.org/review/26391
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2018-03-09 16:10:32 +00:00
Pascal Quantin 4e6d989df4 Add MaxMindDB 1.3.2 library to Windows
Change-Id: I328b6a05cc356be59ac63e80eae55a832bf76a47
Reviewed-on: https://code.wireshark.org/review/26347
Petri-Dish: Pascal Quantin <pascal.quantin@gmail.com>
Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
2018-03-09 11:20:41 +00:00
Gerald Combs 6e32335be6 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>
2018-03-09 00:19:22 +00:00
Gerald Combs 5f35b041c2 MaxMind DB fixups.
Make sure the text we read is null terminated. Properly strip our lines
and chunked strings. Copy over cast and strtod fixes from change 26347.

Change-Id: I0695e35c446c1bd277c53b458b07e428cdd90fb8
Reviewed-on: https://code.wireshark.org/review/26370
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2018-03-08 22:25:59 +00:00
Pascal Quantin 76267f4bc5 maxmind_db.c: fix a memory leak
Change-Id: Ie3484e863363a8d2b9ccb435088886020678d15d
Reviewed-on: https://code.wireshark.org/review/26284
Petri-Dish: Pascal Quantin <pascal.quantin@gmail.com>
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
2018-03-06 22:05:30 +00:00
Pascal Quantin f0f4adc9d9 maxmind_db.c: add an explicit cast to please gcc 7.3.1
Change-Id: Idb2ae052804fb523d6769fe50b5bb4ba45e40f79
Reviewed-on: https://code.wireshark.org/review/26283
Petri-Dish: Pascal Quantin <pascal.quantin@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2018-03-06 21:38:42 +00:00
Gerald Combs a1da75c554 Transition from GeoIP Legacy to MaxMindDB.
MaxMind is discontinuing its legacy databases in April in favor of
GeoIP2, which use a newer database format (MaxMind DB). The reference C
library (libmaxminddb) is available under the Apache 2.0 license which
isn't quite compatible with ours.

Add mmdbresolve, a utility that reads IPv4 and IPv6 addresses on stdin
and prints resolved information on stdout. Place it under a liberal
license (MIT) so that we can keep libmaxminddb at arm's length. Add
epan/maxmind_db.[ch], which spawns mmdbresolve and communicates with it
via stdio.

Migrate the preferences and documentation to MaxMindDB.

Change the IPv4 and IPv6 asnum fields to FT_UINT32s. Change the
geographic coordinate fields to FT_DOUBLEs.

Bug: 10658
Change-Id: I24aeed637bea1b41d173270bda413af230f4425f
Reviewed-on: https://code.wireshark.org/review/26214
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2018-03-06 18:02:21 +00:00