Commit Graph

52 Commits

Author SHA1 Message Date
John Thacker 5ef4da4d98 epan: Prevent buffer overflows in some built-in addr_to_str types
Several of the constant length string built in address types don't
check to see if the buf_len passed in is long enough to write
the string.

This can cause buffer overflows, e.g. with a custom column with
many FT_ETHER fields.
2022-07-05 21:56:54 +00:00
João Valverde d7322e757e epan: Use host byte order with AT_NUMERIC
Use host byte-order with AT_NUMERIC to make it more generic
and practical.

Change openSAFETY to pass addresses in host byte-order (the
previous code assumed they were in little-endian).

Plus a few cleanups.
2022-06-23 16:58:07 +01:00
Roland Knall 4c768f54a7 epan: Make AT_NUMERIC behave more safely
Implement a better handling of byte sizes as well as preventing
possible memory bleeds

Fixes: 18147
2022-06-23 11:00:51 +02:00
Roland Knall 300befc12a epan: Numeric address type
Add a numeric address type analog to StringZ for
protocols who only use numeric values as addresses
with no further handling.

e.g. IAT protocols which only enumerate the devices
2022-06-17 08:56:05 +00:00
João Valverde c5a19582e4 epan: Convert to use stdio.h from GLib
Replace:
    g_snprintf() -> snprintf()
    g_vsnprintf() -> vsnprintf()
    g_strdup_printf() -> ws_strdup_printf()
    g_strdup_vprintf() -> ws_strdup_vprintf()

This is more portable, user-friendly and faster on platforms
where GLib does not like the native I/O.

Adjust the format string to use macros from intypes.h.
2021-12-19 19:29:53 +00:00
João Valverde 18c155a3ca wsutil: Remove ip6_to_str_buf_with_pfx()
Writing a string prefix shouldn't require a specialized function here.
2021-09-17 00:08:41 +01:00
João Valverde 364df939ea wsutil: Rewrite ip6_to_str_buf() 2021-09-17 00:08:40 +01:00
João Valverde 24fd8c6740 Move more numerical epan/*to_str() routines to wsutil 2021-09-16 18:21:14 +01:00
João Valverde 0e50979b3f Replace g_assert() with ws_assert() 2021-06-19 01:23:31 +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
Iain R. Learmonth e1572a6709 ax25: Fix addresses with non-zero SSIDs
Change-Id: Ib718ff56e9f9f5174d09579b7ad85aca18ac9a54
Reviewed-on: https://code.wireshark.org/review/34887
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Roland Knall <rknall@gmail.com>
2019-11-03 13:15:49 +00:00
Guy Harris 20800366dd HTTPS (almost) everywhere.
Change all wireshark.org URLs to use https.

Fix some broken links while we're at it.

Change-Id: I161bf8eeca43b8027605acea666032da86f5ea1c
Reviewed-on: https://code.wireshark.org/review/34089
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-07-26 18:44:40 +00:00
João Valverde 9d9a873d9a Make AT_VINES a built-in type
Change-Id: I5c11cf4c7bee1b2b7072a6a0db5344a6b8a569ac
Reviewed-on: https://code.wireshark.org/review/29326
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot
Reviewed-by: João Valverde <j@v6e.pt>
2018-08-29 19:36:43 +00:00
Robert Sauter eefa76a7c8 address_types: fix returned length of eui64_addr_to_str
Change-Id: I5ed1f20419b45c2d443953eaf74b540d4fcc23c6
Reviewed-on: https://code.wireshark.org/review/26090
Petri-Dish: Roland Knall <rknall@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Roland Knall <rknall@gmail.com>
2018-03-07 23:05:28 +00:00
Stig Bjørlykke 7176b32166 addr: Include trailing '\0' in length from ipv6_to_str()
All other 'addr_to_str' functions does include the trailing '\0'.

This is a bug introduced in g7507b11e.

Change-Id: I6ac2be6d8aedf5c7fbea9dfe67b4d2b4c7f50a6f
Reviewed-on: https://code.wireshark.org/review/26159
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Michael Mann <mmann78@netscape.net>
2018-02-28 01:13:08 +00:00
Dario Lombardo 55c68ee69c epan: use SPDX indentifiers.
Skipping dissectors dir for now.

Change-Id: I717b66bfbc7cc81b83f8c2cbc011fcad643796aa
Reviewed-on: https://code.wireshark.org/review/25694
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-02-08 19:29:45 +00:00
Guy Harris a6167ef73d Don't cast away constness if it's not necessary.
Change-Id: Ie87983f5cbe38266e4f522613b21d25d67ef328f
Reviewed-on: https://code.wireshark.org/review/25360
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-01-18 05:51:44 +00:00
João Valverde fe8d897e25 sizeof(buf) is not what you want here
Change-Id: Iaf3463006b93c9acdc27f59fcbbea92df1d2fd7d
Reviewed-on: https://code.wireshark.org/review/24164
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot
Reviewed-by: João Valverde <j@v6e.pt>
2017-10-29 15:15:41 +00:00
João Valverde 7507b11ec4 Improve our ip6_to_str_buf() implementation
Change-Id: I02b5d01797e526299a6dc5a031662cb78e4f8423
Reviewed-on: https://code.wireshark.org/review/24163
Reviewed-by: João Valverde <j@v6e.pt>
2017-10-29 15:15:31 +00:00
Guy Harris e1ef732c11 Get rid of MAX_IP_STR_LEN and MAX_IP6_STR_LEN.
We have WS_INET_ADDRSTRLEN and WS_INET6_ADDRSTRLEN; use them.

Change-Id: Idade0da9fae70d891901acd787b06d21e2ddbc5f
Reviewed-on: https://code.wireshark.org/review/24156
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-10-29 05:51:25 +00:00
João Valverde ac804b59e2 Improve our inet_ntop() wrapper
Also fix buffer length define, as it is not guaranteed to be 46 on
Windows (it never was guaranteed anyway for the libc implementation,
but the likelyhood of being greater was small).

Change-Id: I2db705d86f825765ed32ec70b8d22058b5d629e8
Reviewed-on: https://code.wireshark.org/review/24074
Reviewed-by: João Valverde <j@v6e.pt>
2017-10-26 14:39:00 +00:00
Guy Harris 458c3c026e Add a ws_in6_addr typedef for struct e_in6_addr.
That allows a parallel typedef of ws_in4_addr for guint32.

Change-Id: I03b230247065e0e3840eb87635315a8e523ef562
Reviewed-on: https://code.wireshark.org/review/24073
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-10-26 08:50:34 +00:00
Martin Kaiser bb20b159f3 addr_types: replace DISSECTOR_ASSERT() with g_assert()
DISSECTOR_ASSERT() can be used only when we're in wmem packet scope. It
cannot be used during startup when address types are registered. In
those cases, we must use g_assert().

If we still use DISSECTOR_ASSERT() and an assert is hit, we'll see a
wmem assertion

**
ERROR:../epan/wmem/wmem_core.c:52:wmem_alloc: assertion failed:
(allocator->in_scope)
Aborted

instead of the actual assert output.

Change-Id: Ife12ca3455d56ba4faa2dd6034df8a091d8641ed
Reviewed-on: https://code.wireshark.org/review/22378
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-06-24 10:33:18 +00:00
Jaap Keuter d0565ad22b Properly end address type search by name (CID-1362742)
Search address type by name iterates over an array, but fails to find its end.
Therefore it may dereference invalid pointers, or NULL.

Add the proper check in the for loop and make sure an end condition is always
there in the array searched.

Change-Id: I60ade9d438dc394340b6483b4fcb23e5ce432000
Reviewed-on: https://code.wireshark.org/review/17337
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-08-26 16:49:57 +00:00
Jens Kilian edac72eb7d Increase MAX_DISSECTOR_ADDR_TYPE.
With the recent changes causing some address types to be registered
by their proper dissectors, I ran into the MAX_DISSECTOR_ADDR_TYPE
limit in a new dissector I'm currently writing.

Change-Id: I72f521266af9190e8ad198ace4d6608b6b4d2dee
Reviewed-on: https://code.wireshark.org/review/16091
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2016-06-23 10:45:17 +00:00
Michael Mann 0bf1cb2342 Add address_to_bytes API.
This will copy an address's "byte format" into a buffer.  The original
intended design is for export_pdu functionality, which tries to do
this "manually" for many address types (and creates undesired dependencies)

The default functionality if a "byte format function" isn't provided
(currently the case for all address types) is a memcpy of the address
data.  Providing "address to byte" functions to aid export PDU
functionality will be provided later.

Change-Id: I3703f9e617a8cef09165ad53a0f98c6372676b9b
Reviewed-on: https://code.wireshark.org/review/16070
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2016-06-22 07:47:39 +00:00
Michael Mann debbf7e930 Move AT_VINES address type to VINES dissector.
proto.c still has to deal with FT_VINES, but maybe that
can be refactored to the dissector too.

Change-Id: Iee04eed3b75f91cb62bb7b625dd44baeeb9aebb3
Reviewed-on: https://code.wireshark.org/review/16069
Petri-Dish: Michael Mann <mmann78@netscape.net>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2016-06-22 04:58:54 +00:00
Michael Mann e7b78eb0a6 Move AT_USB to inside USB dissector.
This required some hacking in the conversation table handling, but
still seemed worth it as USB address is not widely used.
Maybe a "is_stringlike" property for address types...

Change-Id: I628a15c17cb1f595bb292130867adbc5bea0f41a
Reviewed-on: https://code.wireshark.org/review/16068
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2016-06-22 04:57:43 +00:00
Michael Mann 04b82a7dc9 Convert AT_SS7PC to a "dissector address type"
The formatting of the address type is determined by a preference in
packet-mtp3.c, so just make MTP3 register the address type.
Use address_type_get_by_name in other dissectors (and export_pdu)
to use the address type.

Change-Id: Ifb32d7de27aeaa23cee8e803e25ffb3c905547b5
Reviewed-on: https://code.wireshark.org/review/15856
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2016-06-13 17:06:38 +00:00
Michael Mann 87b5597ee0 Add address_type_get_by_name
This allows the decoupling of a dissector registering an address type
so it doesn't need to export the returned registered type.

Change-Id: I49c913d042e70bd4b7ea1e964ba9511bb27304f5
Reviewed-on: https://code.wireshark.org/review/15855
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-06-13 05:16:51 +00:00
João Valverde f1ff3208a0 Move ip6_to_str_buf() to to_str.c and make it take the buffer length.
Also make it use ws_inet_ntop6() (rather than implementing the string
conversion ourselves).

Remove ip6_to_str_buf_len().

Change-Id: I1eff3a8941e00987c2ff0c4dcfda13476af86191
Reviewed-on: https://code.wireshark.org/review/15692
Reviewed-by: João Valverde <j@v6e.pt>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-06-06 22:00:41 +00:00
João Valverde 8bee8bad81 Add inet_pton/inet_ntop interface to libwsutil
Change-Id: Ifc344ed33f2f7ca09a6912a5adb49dc35f07c81f
Reviewed-on: https://code.wireshark.org/review/13881
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: João Valverde <j@v6e.pt>
2016-02-19 15:55:09 +00:00
João Valverde 5e6d45ca98 Make address_to_display() use proper (non-)constness
Don't return allocated memory as a const pointer.

Fixes multiple [-Wcast-qual] warnings.

Change-Id: Ie9ceac27fa2a5eba41a5392ac983ff28c3939239
Reviewed-on: https://code.wireshark.org/review/12267
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2015-11-29 00:25:11 +00:00
João Valverde 3df2333155 Remaining ADDRESS macro to address function conversions
Change-Id: I8bc9af431e70243b05f4f0ce8c2b8ee451383788
Reviewed-on: https://code.wireshark.org/review/11463
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2015-11-03 12:20:34 +00:00
João Valverde 26ebfef4bb Don't display duplicate addresses without name resolution enabled
Change-Id: Ieb88e2632401cbf50c4ae51768a64df64d54a45d
Reviewed-on: https://code.wireshark.org/review/10497
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2015-09-25 21:12:01 +00:00
Guy Harris df5a315048 Fix address resolution for columns.
Have address_to_name() be a routine that takes an address and returns a
string with a "sufficiently long" lifetime for use in columns, using the
address type's addr_name_res_str routine for most address types, rather
than having a too-small set of address types wired into it.  It replaces
both the internal solve_address_to_name() routine and get_addr_name(),
and can, for example, handle the special WLAN address types rather than
leaving them unresolved even with an ethers file.

Change-Id: Id09bc412adf5d2752155650a14a77c5378af2e42
Reviewed-on: https://code.wireshark.org/review/9475
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-07-03 02:21:20 +00:00
Alexis La Goutte d2720ecca7 Address types: fix no previous prototype for ... [-Wmissing-prototypes]
address_types.c:230:14: warning: no previous prototype for 'ipv4_name_res_str' [-Wmissing-prototypes]
address_types.c:237:5: warning: no previous prototype for 'ipv4_name_res_len' [-Wmissing-prototypes]
address_types.c:386:14: warning: no previous prototype for 'ipv6_name_res_str' [-Wmissing-prototypes]
address_types.c:393:5: warning: no previous prototype for 'ipv6_name_res_len' [-Wmissing-prototypes]
address_types.c:509:14: warning: no previous prototype for 'fcwwn_name_res_str' [-Wmissing-prototypes]
address_types.c:538:5: warning: no previous prototype for 'fcwwn_name_res_len' [-Wmissing-prototypes]

Change-Id: I6cf44b887d9e35fb76bd1840444074c9102b4d2b
Reviewed-on: https://code.wireshark.org/review/7508
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Reviewed-by: Michael Mann <mmann78@netscape.net>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2015-03-03 15:36:23 +00:00
Guy Harris 3108bf8d2e Fix typo caught by Coverity - wrong structure members being tested.
CID 1271732

Change-Id: I12b610a0a28fcc790ffb041ca88624e014f68ab5
Reviewed-on: https://code.wireshark.org/review/7465
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-03-02 03:00:14 +00:00
Guy Harris 9ac60ff0df address_to_string routines need to remember the beginning of the buffer.
Either they don't have a pointer into the buffer that they advance, in
which case strlen(buf)+1 works just fine, or they do, in which case

	1) they'd better save the pointer to the beginning of the
	   buffer, so they can figure out how long the string is when
	   they're done

and

	2) they don't need to use strlen(), they can just subtract the
	   pointers.

Bug: 11016
Change-Id: I81ce9d517336a15bd81f0c6225756ce5178ec6cf
Reviewed-on: https://code.wireshark.org/review/7424
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-02-27 04:16:57 +00:00
Guy Harris 6765bf722a Fix generation of address-with-resolution strings.
XXX_to_str routines should return the length, in bytes, of the generated
string, including the terminating '\0'.

As their reutrn values include the terminating '\0', we need to subtract
1 from the return value if, when appending the ")" after the address
string, we want to skip past the address string rather than skipping
past the terminating '\0'.

Change-Id: Ibfd41e6d7152d05070706e6d76fc3e56a097a75b
Reviewed-on: https://code.wireshark.org/review/7324
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2015-02-23 02:51:17 +00:00
Michael Mann 8d5da72ff9 Add tvb_address_with_resolution_to_str.
Convert dissectors to using the API where appropriate.

Change-Id: I059582f73a75635d4a0338d02d4c4b212162480b
Reviewed-on: https://code.wireshark.org/review/7296
Petri-Dish: Michael Mann <mmann78@netscape.net>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2015-02-22 02:53:48 +00:00
Pascal Quantin a99cc2fd0b address_types.c: fix a "conditional jump or move depends on uninitialised value" error found by Valgrind
Change-Id: Ic752bb6aa1ba56e113895fcbed52f417ac0128f7
Reviewed-on: https://code.wireshark.org/review/7272
Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
2015-02-20 11:37:52 +00:00
AndersBroman ca68a7adc3 Add some casts to satisfy the various compilers.
Change-Id: I7687fc0b433774fe447757af00bdaa2fc44ac59d
Reviewed-on: https://code.wireshark.org/review/7254
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2015-02-19 14:23:03 +00:00
Michael Mann 8d16ac46d5 Add name resolution support to address type.
Add address_with_resolution_to_str API that returns address string + name resolution in the format %s (%s), first string is resolved name (if available) and second string is raw address string.

Convert AT_FCWWN to using proper name resolution format

First use of address_with_resolution_to_str with field types in proto.c

Change-Id: I2ae77c29a4ffc30bb919fbec00f06629830898c2
Reviewed-on: https://code.wireshark.org/review/7196
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2015-02-19 13:09:41 +00:00
Michael Mann b2c81bb9e8 Make get_manuf_name return a const string.
Model get_manuf_name after get_ether_name so that a string (either name resolved or colon-separated bytes) is always stored in a hash table.  This will make name resolution of addresses perform a little better because it doesn't have to worry about the wmem_allocator.

Change-Id: If976fe7b0c3f9cd053225096c2ac05418f061af6
Reviewed-on: https://code.wireshark.org/review/7081
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2015-02-16 12:47:02 +00:00
Bill Meier 9c866ff971 Replace tabs by spaces when editor modelines has "expandtab"
Change-Id: If7a6f2697be732ae4f94ed8b845fd293c32510f7
Also: tabs-stops should be 8
Reviewed-on: https://code.wireshark.org/review/7100
Reviewed-by: Bill Meier <wmeier@newsguy.com>
2015-02-13 17:34:53 +00:00
Anders Broman 53228c4bd8 Revert "Make get_manuf_name return a const string."
This reverts commit 797ea88aef.

Change-Id: I9bc2cef0051d88c6374c6f1868b0250cba3edbd4
Reviewed-on: https://code.wireshark.org/review/7076
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2015-02-12 08:34:05 +00:00
Michael Mann 797ea88aef Make get_manuf_name return a const string.
Model get_manuf_name after get_ether_name so that a string (either name resolved or colon-separated bytes) is always stored in a hash table.  This will make name resolution of addresses perform a little better because it doesn't have to work about the wmem_allocator.

Change-Id: I80f465ae0845290255a659ab63310ac3cc35506e
Reviewed-on: https://code.wireshark.org/review/7075
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2015-02-12 07:36:20 +00:00
Michael Mann 8ff944d4ab Add fixed length function for address types.
This allows for even more cleanup with respect to how address types are handled, including removing address_to_str.c.  Most of the functionality was folded into address_types.c, but the remainder was just dispersed because it didn't make sense to keep the file.

Change-Id: Id4e9391f0c3c26eff8c27b362e4f7a1970d718b4
Reviewed-on: https://code.wireshark.org/review/7038
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2015-02-09 03:49:13 +00:00
Michael Mann 2875cd382f Eliminate the hf member out of the address structure.
Using the new address type registration, dissectors can create their own address types with their own (column) filters attached to them, eliminating the need for an address to keep track of a hf_ field.

Change-Id: I2bbec256a056f403a7ac9880d5d76a0b2a21b221
Ping-Bug: 7728
Reviewed-on: https://code.wireshark.org/review/7037
Reviewed-by: Michael Mann <mmann78@netscape.net>
2015-02-09 03:48:53 +00:00