Commit Graph

242 Commits

Author SHA1 Message Date
João Valverde 32f88ad22c wmem: Remove strbuf max size parameter
This parameter was introduced as a safeguard for bugs
that generate an unbounded string but its utility for
that purpose is doubtful and the way it is being used
creates problems with invalid truncation of UTF-8
strings.

Rename wmem_strbuf_sized_new() with a better name.
2022-12-03 01:54:52 +00:00
Guy Harris ea9af624cd epan: eliminate timezone buffer.
Instead of formatting into a fixed-length buffer a string that's empty
if the timezone name is not to be shown and is a space followed by the
timezone name if it is to be shown, just pass to snprint_abs_time_secs()
both a separator string and a timezone name string, with both being
empty strings if the timezone name is not to be shown, and with the
first being " " and the second being the timezone name if the timezone
name is to be shown, with the separator printed before the timezone
name.

That way, we don't have to worry about how big the buffer needs to be.
2022-10-28 14:15:47 -07:00
João Valverde 267954cda2 epan: Increase timezone buffer size
Some internationalized strings can exceed this size and become
truncated with encoding errors.

Fixes #18562.
2022-10-28 14:46:13 +01:00
João Valverde 0047ca961f dfilter: Add support for entering time in UTC
Add the option to enter a filter with an absolute time
value in UTC. Otherwise the value is interpreted in
local time.

The syntax used is an "UTC" suffix, for example:

    frame.time == "Dec 31, 2002 13:55:31.3 UTC"

This also changes the behavior of "Apply Selected as filter".
Fields using a local time display type will use local time
and fields using UTC display type will be applied using UTC.

Fixes #13268.
2021-12-30 17:53:09 +00:00
João Valverde 62c9f333f7 epan: More abs_time_to_str() cleanups
Use abs_time_to_str() to implement abs_time_secs_to_str().

Misc cleanups.
2021-12-29 13:50:21 +00:00
João Valverde 7e041118d8 epan: Add back ABSOLUTE_TIME_NTP_UTC representation
It is a special case the prints "NULL" if time is zero.
2021-12-29 00:30:17 +00:00
João Valverde 445dcd3117 epan: Extend abs_time_to_str() with a flags argument 2021-12-28 04:05:20 +00:00
João Valverde 865e2a3754 epan: Refactor abs_time_to_str()
Refactor the common code in abs_time_to_str() and
abs_time_secs_to_str() into separate functions, to
avoid code duplication and improve maintainability.
2021-12-28 01:49:06 +00:00
João Valverde a566076839 epan: Move time display types to field_display_e
This makes it easier to understand the code, avoids conflicts
and ugly and unnecessary casts.

The field display enum has evolved over time from integer types
to a type generic parameter.
2021-12-27 22:31:31 +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
Evan Huus f9ac0f40f7 to_str: scope decode_bits_in_field
Mostly straightforward. The only complication was
proto_tree_add_split_bits_crumb which needed some manipulation to
guarantee a non-null tree so we could use its memory scope.

This is one of the last non-dissector uses of wmem_packet_scope!
2021-10-05 04:42:13 +00:00
Tomasz Moń 7b82110092 USB HID: Parse bit fields with correct bit order
Implement little endian support for tvb_get_bits family of functions.
The big/little endian refers to bit numbering within an octet. In big
endian, the most significant bit is considered bit 0, while in little
endian the least significant bit is considered bit 0.

Add encoding parameters to proto tree bits format family functions.
Specify ENC_BIG_ENDIAN in all dissectors using these functions except in
USB HID that requires ENC_LITTLE_ENDIAN to work correctly.

When formatting bits values, always display most significant bit on the
leftmost position regardless of the encoding. This results in no gaps
between octets and makes the displayed value comprehensible.

Close #4478
Fix #17014
2021-09-26 18:16:28 +02:00
João Valverde 8c4a479c52 Move more numerical functions to wsutil/to_str.h 2021-09-16 20:55:03 +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 8a584222f1 Move epan/*to_str_back() functions to wsutil 2021-09-16 15:53:14 +00:00
Jorge Mora 981ec7f3c7 iwarp_mpa: fix iWarp MPA for NFS-over-RDMA
On the first packet of the conversation, the MPA layer is
dissected correctly followed by the DDP, RDMAP, RPC-over-RDMA,
RPC and NFS layers. The MPA layer sets the TCP conversation as
MPA protocol but when it dissects the RPC layer it also sets
the TCP conversation as RPC protocol thus overwriting the previous
protocol.

Added new port type PT_IWARP_MPA so that when the RPC layer
is dissected it does not overwrite the default protocol for
the TCP conversation which has already been set to MPA.

Fixes #15869.
2021-08-31 08:14:31 +00:00
João Valverde c3bd5c9d91 Move bytes_to_str() to wsutil
This utility function is useful outside of epan. Move it to wsutil
and export the interface.

The move isn't completely clean as it requires duplicating two small
inline functions but that was necessary to avoiding moving too much at
once.
2021-07-29 17:23:04 +00:00
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 72ea33ae20 epan: Change bytes_to_str() length argument to a size_t 2021-06-20 18:58:10 +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
Gerald Combs d5f2657825 epan: Limit our bits in decode_bits_in_field.
Limit the number of bits we process in decode_bits_in_field, otherwise
we'll overrun our buffer. Fixes #16958.
2020-11-07 19:51:20 +00:00
Guy Harris a58ed646aa Handle relative times with >2^31 seconds.
Make display_signed_time() take a 64-bit signed number of seconds, and,
in calls to it, cast the argument to gint64, not gint32.

Addresses issue #16909.
2020-10-18 02:06:07 -07:00
Gerald Combs 898e390c2c Fix the Windows build.
Fetch time zone names using _tzname.
2020-09-02 12:36:53 -07:00
Guy Harris a1762dcbb0 get_zonename(): don't convert _tzname[] values to UTF-8.
Now that we're setting the C-language locale to use the UTF-8 code page,
they're already *in* UTF-8; g_locale_to_utf8() doesn't treat the
C-language locale's code page as the "locale" code page, it uses the
system code page, so it reads a UTF-8 string as being in some local code
page's encoding and proceeds to mangle it in the process of converting
it to UTF-8.

Closes #16811 (closed)
2020-09-01 23:52:35 -07:00
Anders Broman 7c7f5765d3 For a zero time stamp preserve the base time but put "(0)" in front.
Make it more obvious that the time value is Zero.

Change-Id: Idca96185d869f10cf0d2b8ab6aaccb879dfc1ec2
Reviewed-on: https://code.wireshark.org/review/38135
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-08-12 10:59:53 +00:00
Anders Broman a72e415451 For a zero time stamp don't print the EPOCH, print NULL.
Change-Id: I3b4a0bb3f392dc14b22d0a63ad1a7751d942e1e5
Reviewed-on: https://code.wireshark.org/review/38120
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-08-11 10:12:31 +00:00
Stefan Metzmacher 17a6916a21 epan/to_str: change MAX_BYTE_STR_LEN from 48 to 72
We want things like aes-256 keys to be displayed completely.

Change-Id: I746f3282440c036cfb60263be40e3b3a6ed859c2
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-on: https://code.wireshark.org/review/35703
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-01-26 19:31:34 +00:00
Michael Mann 01d7793976 Add proto_tree_add_item_ret_time_string
A few dissectors need the functionality of adding a time field to a proto_tree
while also needing the "time to string" value (typically to show on a tree above).
The functionality to do "get value from tvb and convert to string" was being done
in packet-ntp.c.
Instead proto_tree_add_item_ret_time_string can be used with various encoding to
get the necessary functionality with less code duplication.

ENC_TIME_MIP6 was added as a result of the refactoring.
ABSOLUTE_TIME_NTP_UTC was added as another potential "base" type for time fields.

Change-Id: Ie460c33370b0af59ef60bdab893ce9d6eb23b94f
Reviewed-on: https://code.wireshark.org/review/34390
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-08-29 13:31:48 +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
Martin Boye Petersen 1a2aa0e901 to_str: Fixed incorrect order of checks in bytestring_to_str.
Issue revealed by commit 281dd22da9.
The commit that revealed the issue allowed bytestring_to_str to be
called when len was 0 and *ad was NULL causing a dissector bug to be reported.

Change-Id: I01c2c04154e0514dc2702b5c1c43ed5074d0ac11
Reviewed-on: https://code.wireshark.org/review/30421
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2018-10-30 12:47:19 +00:00
Stig Bjørlykke 68e7f51d0e epan: Use UTF8 horizontal ellipsis to indicate truncation
Use UTF8_HORIZONTAL_ELLIPSIS to indicate string truncation in
bytestring_to_str() and bytes_to_str().

We also use UTF8_HORIZONTAL_ELLIPSIS in the Packet List.

Change-Id: Iaf5c2de97fa71369a8f29ac65fa81f71ed814752
Reviewed-on: https://code.wireshark.org/review/29291
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2018-08-27 08:07:11 +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
Michael Mann 147e491025 Convert PT_EXCHG into using conversation endpoints
Change-Id: Id5857a58513c38dd0ab5b30b61113bcc14e1ecee
Reviewed-on: https://code.wireshark.org/review/24258
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-11-06 15:19:15 +00:00
Michael Mann 23afd28daf Convert TIPC to use endpoint conversations
Change-Id: Iab03ebbfc982bf7182851f63c17fa59bc71d7709
Reviewed-on: https://code.wireshark.org/review/24219
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2017-11-05 23:17:32 +00:00
Michael Mann 66b441f3d6 Add ability to create endpoints through conversations
Add endpoint information to the packet_info structure for dissectors
to potentially use as their data to create conversations.

This patch includes a simple "example" of using conversation_create_endpoint
with TDMoP.  The assignment of the PT_TDMOP "port type" has been replaced by
setting ENDPOINT_TDMOP within the endpoint structure.  Then when subdissectors
of TDMoP call find_or_create_conversation(), it implicitly picks up the
conversation information set by TDMoP

Change-Id: I11dc29989cccd3b0f0349ee901babb455ca02d19
Reviewed-on: https://code.wireshark.org/review/24190
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Andrew Chernyh <andrew.chernyh@gmail.com>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-11-01 02:41:45 +00:00
Michael Mann d597b5d61e Remove port_type values not set in pinfo->ptype
NCP and SBCCS values used for conversation (endpoints) and not
to pass "type" to subdissectors.

Change-Id: I56a13d2bb7d718b340e9b5a102c43f6e0012bfb9
Reviewed-on: https://code.wireshark.org/review/24174
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-10-30 02:26:59 +00:00
Michael Mann abfb644117 Add conversation endpoint type
For the moment this mirrors the port_type enumeration (PT_XXX), but the
intent is to move away from using "port types", eliminating most (if not
all)

Added conversation_pt_to_endpoint_type() so that conversations deal with the
correct enumeration.  This is for dissector that use pinfo->ptype as input
to conversation APIs.  Explicit use of port types are converted to using
ENDPOINT_XXX type.

Change-Id: Ia0bf553a3943b702c921f185407e03ce93ebf0ef
Reviewed-on: https://code.wireshark.org/review/24166
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-10-29 16:53:57 +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
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
Guy Harris 4e5408cda9 Fix backwards #if defined.
Left over from some stuff I was fiddling with.

Bug: 11785
Change-Id: Ifb06e8b65db65037b336c46e5e180012ae5b7a59
Reviewed-on: https://code.wireshark.org/review/19487
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-01-01 05:46:37 +00:00
Guy Harris 8909dff721 Always use the Windows time zone code on Windows.
We *have* to use the Windows code on Windows for the reasons given in
the comment.  However, some versions of Visual Studio have a time.h that
CMake thinks defines tzname[] (which the header will do under some
circumstances), so HAVE_TZNAME gets defined on Windows.  We check for
Windows *before* checking for HAVE_TZNAME - or HAVE_STRUCT_TM_TM_ZONE.

Bug: 11785
Change-Id: I61360daf08203dbd9d109a87c05727b4dbecea66
Reviewed-on: https://code.wireshark.org/review/19483
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-01-01 05:19:49 +00:00
Guy Harris d7fe514fc0 Improve support for single-character fields and filter expressions.
Add an FT_CHAR type, which is like FT_UINT8 except that the value is
displayed as a C-style character constant.

Allow use of C-style character constants in filter expressions; they can
be used in comparisons with all integral types, and in "contains"
operators.

Use that type for some fields that appear (based on the way they're
displayed, or on the use of C-style character constants in their
value_string tables) to be 1-byte characters rather than 8-bit numbers.

Change-Id: I39a9f0dda0bd7f4fa02a9ca8373216206f4d7135
Reviewed-on: https://code.wireshark.org/review/17787
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-09-19 02:51:13 +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
Guy Harris 6febe27586 Give the time_[m]secs_to routines names that begin with "[un]signed_".
Indicate whether they take a signed time delta or an unsigned time
delta.

Export unsigned_time_secs_to_str() while we're at it.

Change-Id: I0fbe87f1825efa886364caa61a3358b79d285947
Reviewed-on: https://code.wireshark.org/review/15324
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-05-09 22:55:00 +00:00
Guy Harris 4013776eec Handle -2^31 as a negative time-in-seconds.
Its absolute value *is* expressible as an unsigned 32-bit value, so have
time_secs_to_str_buf(), for negative values, just put a - at the front
of the string and then pass the absolute value to
time_secs_to_str_buf_unsigned().

Change-Id: I87252fe541d9aac4902f81493c9f032ec3ed1500
Reviewed-on: https://code.wireshark.org/review/15323
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-05-09 22:21:42 +00:00
Guy Harris 1b1614913f Shuffle some routines to put absolute-time and relative-time code together.
Put the routines that handle absolute time ("relative to the Epoch")
together and the routines that handle relative time together.

Change-Id: I15256921091ab67a1d92026385bf1b27aa52b404
Reviewed-on: https://code.wireshark.org/review/15316
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-05-09 20:26:13 +00:00
João Valverde ae9e311480 Use AC_STRUCT_TIMEZONE
Change-Id: I96c12dce662691d37d6eb6c1893c5e9d91a8ea6f
Reviewed-on: https://code.wireshark.org/review/14753
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: João Valverde <j@v6e.pt>
2016-04-02 22:18:46 +00:00
João Valverde cbc36cbd97 Remove constness from bytestring_to_str() [-Wcast-qual]
Change-Id: I7f942787dfdc4f76dd0ad5111d1eb528b20f0ba9
Reviewed-on: https://code.wireshark.org/review/13011
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Reviewed-by: João Valverde <j@v6e.pt>
2016-01-07 22:40:30 +00:00
Michael Mann 648cf995b1 Make other_decode_bitfield_value private to proto.c.
This is further encouragement to not try to manually create a bitstring while formatting a field.

Change-Id: I4efbeb39a210cf1fd26203cd8560859276b333b0
Reviewed-on: https://code.wireshark.org/review/10494
Petri-Dish: Michael Mann <mmann78@netscape.net>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2015-09-13 00:15:35 +00:00