Commit Graph

1342 Commits

Author SHA1 Message Date
João Valverde eda38f5f2d Replace g_utf8_make_valid() with own function
The function ws_utf8_make_valid() is all-around better and
also does maximal substitution of subparts.
2023-02-08 11:21:19 +00:00
João Valverde a66b5080c3 Make wmem and wsutil a single logical library
We want to do more sophisticated processing of UTF-8 in wmem and
for that we want to use the unicode utility functions in wsutil.

We also want to use wmem scoped memory in wsutil unicode utility
functions.

This introduces a circular dependency. Fix that by making both
the same library and removing the sanitary cordon separating
them.

We still need to be mindful of public header  depencies of wmem on
wsutil because wmem.h is included in wireshark.h and we want to
be parsimonious with the use of global includes.
2023-02-08 11:21:19 +00:00
João Valverde 84f963dfa2 Move ui/version_info.[ch] to wsutil 2023-02-07 23:17:37 +00:00
David Perry 71a77a4a5d Correct function signatures for buffer functions 2023-02-07 19:52:37 +00:00
João Valverde 7c156d9ac4 Add a #define HAVE_MSYSTEM and use it
In certain situations using __MINGW64__ is not correct.
We want to have the condition apply using MinGW-w64 but also
using MSYS2, which the __MINGW64__ condition alone does not
capture.

Add a HAVE_MSYSTEM C define and use it where appropriate.
2023-02-06 19:39:33 +00:00
João Valverde 66bd99f1a8 wsutil/filesystem: Fix potential memory leak
We now use the 'install_prefix' variable on multiple platforms,
not just MSYS2.
2023-02-06 19:39:33 +00:00
João Valverde 02238edf92 Do not require using wsgcrypt.h
The reason to use wsgcrypt.h was to wrap it around DIAG_OFF()
macros and that should no longer be necessary.
2023-02-06 15:52:10 +00:00
João Valverde d70e174ca0 Remove wsutil/netlink.h workaround 2023-02-06 15:04:46 +00:00
João Valverde b07ab25a1c CMake: Cleanup unnecessary linking with shared libraries 2023-02-06 15:04:46 +00:00
João Valverde 2855c8ec46 Convert unicode-utils.[ch] to 4-space indentation 2023-02-06 15:03:49 +00:00
João Valverde 9feb85ce4d Move get_utf_8_string() to wsutil 2023-02-06 15:03:49 +00:00
Gerald Combs 894e8c46c6 Revert "Enable rpathification and working relocation on Linux"
This reverts commit 7a346c398a.
2023-01-30 22:30:56 +00:00
João Valverde 7a346c398a Enable rpathification and working relocation on Linux
Dumpcap depends on wsutil.so. The path to the shared library
is encoded in the RPATH (or RUNPATH) property of ELF binaries.
This is currently an absolute path on most Unixy systems.

Dumpcap could not be made to work with a relative RPATH because it
uses elevated privileges and some loaders will ignore relative
RPATHs and non-standard paths under those circumstances, because of
(justified) security concerns.

To enable relocation of the program we link dumpcap statically
with wsutil instead.

This provides a fully working relocatable installation on Linux
and other platforms that support relative RPATHs.
2023-01-29 23:38:00 +00:00
Gerald Combs b8f0d17af9 wsutil: Filesystem routine updates.
Make sure init_plugin_dir and get_doc_dir uses the same logic as
get_datafile_dir. Update each so that the xxx_DATA_DIR and
xxx_PLUGIN_DIR environment variables take precedence.

CMake's ENABLE_APPLICATION_BUNDLE determines whether or not we're using
an application bundle layout, so check for it instead of __APPLE__.
2023-01-29 20:35:18 +00:00
João Valverde abdaed1103 Add support for configuration path relocation on Unix
Get the installation prefix from the program dir. We have code
to obtain the directory where the executable resides for all
platforms we support, Linux, BSDs, Apple, etc.

On less well-known platforms where this isn't true (POSIX does not
define any standard interfaces for this) we fallback on
using a hard-coded installation prefix, like we have been doing
until now.

The path relocation allows the whole installation tree to be moved
without having to recompile the program. But note there are other
requirements for shared libraries to have full support for relocation.
This is only partial support.

We now use a header to pass the relative path definitions to avoid
excessively long compilation command lines as the number of #defines
increases.
2023-01-26 18:43:20 +00:00
João Valverde 39124f2f8f Fix Personal Extcap folder path
The personal extcap folder $XDG_CONFIG_DIR/wireshark on Linux is
inconsistent with the global extcap folder (lib/wireshark/extcap)
and personal plugins folder (.local/lib/wireshark/plugins) and also
the configuration folder should not contain architecture-specific files.

The extcap personal folder is changed from:

    .config/wireshark/extcap

to:

    .local/lib/wireshark/extcap
2023-01-20 22:30:26 +00:00
João Valverde c66fc43e5b GUI: Ship authors as a Qt resource file 2023-01-20 13:35:03 +00:00
João Valverde 597bcca9ee wsutil: Add get_docfile_path() 2023-01-20 10:16:20 +00:00
João Valverde 06519be205 Install documentation (HTML manuals) to DOCDIR
Install documentation to DOCDIR instead of DATADIR.
The code must be fixed to open the Help URLs from
this new path.

This only affects Unix-like FHS platforms. Windows
installation does its own thing.

Needs testing with macOS packaging.
2023-01-19 01:40:59 +00:00
Gerald Combs 5a9812ab61 AppRun: Set various paths
Set our ld library path and our data, extcap, and plugin directories.
Document WIRESHARK_EXTCAP_DIR and WIRESHARK_PLUGIN_DIR. Note that we
might want to set our various directories relative to the program path.
2023-01-18 20:37:08 +00:00
João Valverde fe7bfdf6ca CMake: Require explicit installation of development headers
Develpment headers are a sizeable part of the binary installation
and most users won't ever require them. It's recommended to package
them separately in a devel package or SDK.

Create a CMake installation component for development headers
and add the EXCLUDE_FROM_ALL property.

Headers can be installed using the invocation:

    cmake --install <dir> --component Development
2023-01-18 03:35:13 +00:00
João Valverde a23bab971e MinGW: Disable -Wcast-function-type warnings 2023-01-14 14:52:53 +00:00
João Valverde 6bfeecb562 MinGW: Fix warnings wiht ws_strptime() 2023-01-14 14:52:53 +00:00
João Valverde f3152af8a0 MinGW: Fix -Wsign-compare 2023-01-13 22:41:04 +00:00
João Valverde 78dffe34d5 MinGW: Fix -Wold-style-declaration 2023-01-13 22:41:04 +00:00
João Valverde 10d197c64d MinGW: Fix -Wstrict-prototypes 2023-01-13 22:41:04 +00:00
João Valverde d902cabd3f MinGW: Fix -Wformat 2023-01-13 15:48:03 +00:00
João Valverde 8cd74b7cd4 MinGW: Fix -Wunused-function 2023-01-13 15:48:03 +00:00
João Valverde d00bd20fea MSYS2: Fix system installation
Make the "ninja install" target in the MINGW64 shell work and
allow Wireshark to run from the msys2 installation, besides
the build directory.

To clarify the names used here MSYSTEM is the distribution with a
Linux-like environment for Windows. MINGW is the toolchain.

It is possible to use MinGW without MSYS2 and we generally select
the CMake variables WIN32/MSVC/MINGW/USE_MSYSTEM taking that into
consideration but that WIN32+MINGW platform is not supported at the
moment and it's unlikely to be supported in the near future.
2023-01-12 14:30:41 +00:00
João Valverde 4c9b0d846c CMake: Reverse debug macros
Originally WS_DISABLE_DEBUG was chosen to be
similar to G_DISABLE_ASSERT and NDEBUG.

However generator expressions are essential for modern CMake
but the syntax is weird and having to use negations makes it
ten-fold worse.

Remove the negation. Instead of changing the CMake variable
reverse the macro definition for WS_DISABLE_DEBUG.

The $<CONFIG:cgs> generator expression with multiple config arguments
requires CMake >= 3.19 so we can't use that yet for a further
syntactical simplification.
2023-01-12 00:59:15 +00:00
João Valverde 25d4a099f7 Remove WS_DISABLE_ASSERT
Assertions can be enabled/disabled using WS_DISABLE_DEBUG. The extra
granularity afforded by WS_DISABLE_ASSERT seems unnecessary.
2023-01-12 00:59:15 +00:00
João Valverde 943bede110 version info: Strip whitespace from a string 2023-01-11 18:52:06 +00:00
Guy Harris 13f3ebc4e5 Add a routine to get the path of an executable given the program name.
That reduces the number of get_progfile_dir() calls, leaving only the
calls that are done either to 1) get the pathname in order to display it
or 2) get the pathname in order to reset the library path.

That makes it easier to figure out which get_progfile_dir() calls are
made to find the directory in which (non-extcap) binaries from Wireshark
are installed and which - if any - are made to figure out the directory
in which *the currently-running executable* are stored.  (Currently,
get_progfile_dir() attemps to get the former, not the latter, so
extcaps in an extcap subdirectory, for example, will get the parent
directory of that subdirectory, *not* the directory in which they weere
installed.)
2022-12-23 23:20:22 +00:00
Gerald Combs 5dcefc7777 wsutil: Make progfile_dir the main program file directory.
If our program file directory has a trailing "/extcap" or "\extcap",
trim it off. This should let extcaps determine the proper data file and
plugin directories. Fixes #15592.
2022-12-22 21:22:04 +00:00
John Thacker 5b96d57b18 protobuf: Do not crash on zero length bytes element
If a field name has been written to the json dumper for
a bytes element (Base64), then a Base64 value must be written
later, even if the value is zero length.

Move the JSON_DUMPER_FLAGS_NO_DEBUG flag to the json_dumper header,
and use it in the protobuf dissector, so that errors in the JSON
dumper state transitions do not abort the application through a
ws_error() call. Use DISSECTOR_ASSERT in that case, since it should
happen only with a dissector bug (as with the zero bytes elements
issue fixed here), not with malformed packets.

Only instantiate the json_dumper and create its output string if
we intend on displaying its output, instead of doing so whenever
we have a message type name.

Fix #18730.
2022-12-16 12:20:30 +00:00
John Thacker 03b4c62be5 cli: Fix copying global profile to personal at startup
Fix up commit 1eeb0c9934
At initial startup, the hash of configuration files used
by profiles doesn't exist yet or is not completely filled.
(Files are only added to the list after initially parsing
the current configuration.)

So, if copying a global profile to the personal directory
at initial startup, just copy all the files from the global
profile.

Also, don't free to_dir and from_dir if we're returning them
in the case of errors.
2022-12-15 14:05:19 +00:00
João Valverde 7fef921875 wslog: Resynchronize UTF-8 display
When displaying the string with encoding errors resynchronize
the display to print the string after the invalid substring.
2022-12-15 11:08:41 +00:00
João Valverde ea8b5fb024 wmem: Add wmem_strbuf_append_c_count() 2022-12-15 11:08:41 +00:00
João Valverde 1f34529839 wmem: Optimize some strbuf functions
The changes in commit 32f88ad22c allow removing some checks that
could speed up the code.
2022-12-15 11:08:41 +00:00
João Valverde 2d3de008f5 CMake: Disable UTF-8 debug checks for release builds
Disable UTF-8 debug checks for release builds for optimization
purposes.

Also remove unused macro that currently lacks a proper use case.

Change version info to be more complete about the build type without
being too verbose.
2022-12-15 01:57:39 +00:00
Gerald Combs cb420c7911 Extcap: Create our fifo in a temporary directory.
Instead of creating a temp file, unlinking it, and creating a fifo with
the same name, add create_tempdir() so that we can create a temporary
directory and create a fifo inside that.

This should avoid a race condition in Carbon Black Cloud antivirus,
which if the timing is right, will stat the initial temporary *file*,
miss the fact that it's been replaced with a *fifo*, and open and steal
data^W^W read from it, leaving dumpcap to contend with the truncated
remains.

Adding the unexpected magic number to cap_pipe_open_live()'s error
message helped to debug this. Leave it in since it's handy to have in
that case.

Ping #15587
2022-12-12 18:34:21 +00:00
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
João Valverde 729ea56b46 wmem: Remove wmem_strbuf_new_label()
Only dissectors are using this function and there is no use case,
as far as I know, that requires its use. Any limitation of length
is imposed transparently by the UI backend.

This function is problematic because it is not Unicode aware and
will truncate a string on an arbitrary byte boundary for multibyte
strings.

Replace its use with a normal strbuf without a length limite and
remove the function because it is not useful and the ITEM_LABEL_LENGTH
parameter does not belong in wmem anyway.
2022-11-30 15:55:54 +00:00
João Valverde 7336190bbc wslog: Check fileno() for errors
fileno() can fail and GLib will assert on negative fd.

Fixes #18684.
2022-11-29 15:41:20 +00:00
João Valverde f3a96bc18c IAX2: Fix UTF-8 string encoding
Fixes #18651.
2022-11-18 11:32:13 +00:00
Jeremy Kerr e1cbe02cce Add Management Component Transport Protocol (MCTP) dissector
This change adds a protocol dissector for the Management Component
Transport Protocol (MCTP). This is a failry simple datagram-based
protocol for messaging between components within a single platform,
typically over I2C, serial or PCIe.

This dissector just implements the header fields, and sequence-number
based message reassembly. Inner protocols will be added as follow-up
changes.

Linux has support for AF_MCTP data, so decode from the MCTP SLL ltype.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
2022-11-15 09:05:05 +00:00
John Thacker f4965d5dec wmem: Make wmem_strbuf_utf8_validate endpptr param optional
Often we don't care about the last valid character, just if
the buffer is valid.
2022-11-06 21:11:36 +00:00
João Valverde 9504b54bc1 unicode-utils: Add a null check to UTF-8 validation
Fixes #18563.
2022-10-30 08:27:13 +00:00
João Valverde 6aa33f0fc9 wmem: Make strbuf_utf8_validate() accept embedded NUL bytes 2022-10-21 10:21:21 +00:00
João Valverde 4eb78424d2 CMake: Add -Werror to test binaries 2022-10-20 18:26:49 +01:00