aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil
AgeCommit message (Collapse)AuthorFilesLines
2022-12-12Extcap: Create our fifo in a temporary directory.Gerald Combs2-17/+61
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-03wmem: Remove strbuf max size parameterJoão Valverde4-69/+21
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-11-30wmem: Remove wmem_strbuf_new_label()João Valverde1-3/+3
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-29wslog: Check fileno() for errorsJoão Valverde1-2/+5
fileno() can fail and GLib will assert on negative fd. Fixes #18684.
2022-11-18IAX2: Fix UTF-8 string encodingJoão Valverde2-0/+46
Fixes #18651.
2022-11-15Add Management Component Transport Protocol (MCTP) dissectorJeremy Kerr1-0/+1
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-06wmem: Make wmem_strbuf_utf8_validate endpptr param optionalJohn Thacker2-5/+20
Often we don't care about the last valid character, just if the buffer is valid.
2022-10-30unicode-utils: Add a null check to UTF-8 validationJoão Valverde1-1/+1
Fixes #18563.
2022-10-21wmem: Make strbuf_utf8_validate() accept embedded NUL bytesJoão Valverde3-2/+57
2022-10-20CMake: Add -Werror to test binariesJoão Valverde2-0/+2
2022-10-19charsets: Don't add illegal Unicode codepoints for UTF-16, UTF-32John Thacker2-0/+17
If a character is not a valid Unicode codepoint, i.e. one of the code points reserved for surrogate pairs or a code point above 0x10FFFF, don't add it to a wmem_strbuf when converting from other encodings but add a replacement character instead, by using a new wmem_strbuf_append_unichar_validated() function. Now we produce valid UTF-8 in various situations where UCS-2 or UTF-32 can encode unpaired surrogate codepoints. Consolidate some related checks that are now redundant. Also add a replacement character to the end of invalid UCS-2 strings with an odd number of bytes, as done with UTF-16 and UTF-32. Fix #18508
2022-10-16Add a #define for REPLACEMENT CHARACTER and use it.Guy Harris3-11/+12
Add UNICODE_REPLACEMENT_CHARACTER as a #define for the Unicode REPLACEMENT CHARACTER code point (0x00FFFD), and use that instead of 0xfffd/0xFFFD/0x00FFFD in cases where that value refers to REPLACEMENT CHARACTER.
2022-10-15TDS: Reject invalid ASCIIJoão Valverde1-0/+3
Fixes #18448.
2022-10-15wslog: Do not print control charactersJoão Valverde3-8/+74
2022-10-14wsutil: Rewrite ws_utf8_char_len() using a lookup tableJoão Valverde2-14/+28
Rewrite for speed and correctness. This implementation is more strict with invalid first bytes (continuation bytes, invalid codepoints and some overlong sequences). Returns 0 instead of -1 for invalid bytes.
2022-10-12wsutil/str_util: Add ws_utf8_truncateJohn Thacker2-0/+38
Add a convenience function to truncate a UTF-8 string to no more than certain length, while ensuring that the string ends with a complete character instead of a partial sequence (by truncating up to 3 additional bytes as necessary.) The common use case is when a valid UTF-8 string is copied into a buffer via snprintf, strlcpy, or strlcat and truncated, to fix up the end of the string and keep the string valid. The buffer holding the string must be large enough, and the string must be valid up to the point of truncation (aside from the possible partial sequence at the end). For speed, the function does not check those conditions. Ping #18412.
2022-10-11wslog: rename console open preference enumJoão Valverde2-5/+5
2022-10-11wslog: Fix console_open registry key nameJoão Valverde2-1/+7
Fix "OpenConsole" registry key to "ConsoleOpen". Add a common macro for the key name.
2022-10-11Windows: Store "gui.console_open" in the Windows registryJoão Valverde5-7/+453
This removes the last dependency of the logging subsystem on the preferences module. The latter is started much later than the former and this is an issue. The Windows-only preference "gui.console_open" is stored in the registry as HKEY_LOCAL_USER\Software\Wireshark\ConsoleOpen. The semantics are exactly the same. The preference is read by the logging subsystem for initialization and then again by the preferences (read/write) so the user can configure it as before. The code to store the preference also in the preferences file was kept, for backward compatibility and because it is not incompatible with using the Registry concurrently. The elimination of the prefs dependency also allows moving the Windows console logic to wsutil and add the functionality to wslog directly, thereby eliminating the superfluous Wireshark/Logray custom log handler. To be able to read the ws_log_console_open global variable from libwireshark it becomes necessary to add a new export macro symbol called WSUTIL_EXPORT.
2022-10-08Add log init message to main()João Valverde1-11/+14
2022-10-08Move print_hex_data_buffer() to wsutilJoão Valverde2-0/+252
Move this generic function to wsutil so it can be used by other libraries.
2022-10-08wmem: Avoid header dependency on wsutilJoão Valverde2-2/+2
Including wireshark.h also pulls some wsutil headers. Avoid that.
2022-10-08wslog: Improve display for UTF-8 stringsJoão Valverde1-14/+11
Print the valid substring as UTF-8, not ASCII+hex.
2022-10-07wiretap: Add enum generationJoão Valverde3-0/+58
2022-10-05wsutil: Improve UTF-8 APIs for debuggingJoão Valverde6-15/+164
In particular add an UTF-8 specific wslog API that should make it easier to interpret invalid encodings.
2022-10-04wslog: Improve help outputJoão Valverde1-3/+8
2022-10-04wslog: Do not leak memoryJoão Valverde1-0/+1
2022-10-02Remove encoding warnings from format_text()João Valverde2-13/+2
The use of format_text() to sanitize strings by dissectors is too widespread to make this check useful. Allow it for now.
2022-09-28Move format_text() to libwsutil and add unit testsJoão Valverde3-0/+633
2022-09-28wslog: Activate message if domain is fatalJoão Valverde1-0/+9
Without requiring extra options like --log-level or --log-domains.
2022-09-28wslog: Add option to make a list of domains fatalJoão Valverde2-18/+88
Add a command line option --log-fatal-domains= and environment variable WIRESHARK_LOG_FATAL_DOMAINS that aborts the programs if a domain in the list is logged to. Negative matches for fatal log domains not implemented for now, pending a relevant use-case.
2022-09-28wslog: Print to stderr with a null error handlerJoão Valverde1-4/+4
For some programs (e.g: unit tests) we want to init the logging subsystem but having to pass an error output handler is overkill and annoying. In that case with a NULL handler printing to stderr by default is almost certainly the best thing to do.
2022-09-27wmem: Remove a redundant ternary operatorJoão Valverde1-1/+1
wmem_strbuf_grow should set the correct size with regard to max_size, if set. In any case passing the actual free "raw" size to g_strlcpy is always the correct thing to do.
2022-09-27wmem: Rename some variablesJoão Valverde2-47/+47
Use length and size consistently. strbuf->len does not include the terminating nul. strbuf->alloc_len includes the terminating nul. Use consistent language and use "length" to mean size without nul byte and "size" to mean size with all bytes, including nul.
2022-09-27Add some UTF-8 debug checks with a compile time flagJoão Valverde2-2/+33
Some older dissectors that predate Unicode and parse text protocols are prone to generate invalid UTF-8 strings. This is a bug and can have safety implications. For example passing invalid UTF-8 to proto_tree_add_string() is a common bug. There are safeguards in format_text() but this should not be relied on as a general solution to the problem. For one, as the name implies, it is only used with representation of a field value, which is not the same as the value itself of an FT_STRING field. Issue #18317 shows another reason why. For now this compile flag only enables extra checks for string ftypes, which covers a subset of proto.h APIs including proto_tree_append_string(). Later is should be extended to other interfaces. This is also not expected to be disabled for release builds because there are still many dissectors that do not correctly handle strings. More work is needed to 1) identify them and 2) fix them. Ping #18317
2022-09-16wmem: Add a wmem_map_foreach_remove functionJohn Thacker3-0/+56
Like wmem_map_remove(), this frees the key/value pair item in the map but not the key or the value itself (which may in fact be the same object.) Not generally a problem, as they'll get freed by the pool. (If someone wants to manage memory themselves, they should probably be using a GHashTable.)
2022-09-15UDPCP: seq-num analysis, and match data and ACKsMartin Mathieson2-0/+26
2022-09-10Dissector names are not protocol names.Guy Harris1-11/+21
A given protocol's packet format may depend, for example, on which lower-level protocol is transporting the protocol in question. For example, protocols that run atop both byte-stream protocols such as TCP and TLS, and packet-oriented protocols such as UDP or DTLS, might begin the packet with a length when running atop a byte-stream protocol, to indicate where this packet ends and the next packet begins in the byte stream, but not do so when running atop a packet-oriented protocol. Dissectors can handle this in various ways: For example, the dissector could attempt to determine the protocol over which the packet was transported. Unfortunately, many of those mechanisms do so by fetching data from the packet_info structure, and many items in that structure act as global variables, so that, for example, if there are two two PDUs for protocol A inside a TCP segment, and the first protocol for PDU A contains a PDU for protocol B, and protocol B's dissector, or a dissector it calls, modifies the information in the packet_info structure so that it no longer indicates that the parent protocol is TCP, the second PDU for protocol A might not be correctly dissected. Another such mechanism is to query the previous element in the layers structure of the packet_info structure, which is a list of protocol IDs. Unfortunately, that is not a list of earlier protocols in the protocol stack, it's a list of earlier protocols in the dissection, which means that, in the above example, when the second PDU for protocol A is dissected, the list is {...,TCP,A,B,...,A}, which means that the previous element in the list is not TCP, so, again, the second PDU for protocol A will not be correctly dissected. An alternative is to have multiple dissectors for the same protocol, with the part of the protocol that's independent of the protocol transporting the PDU being dissected by common code. Protocol B might have an "over a byte-stream transport" dissector and an "over a packet transport" dissector, with the first dissector being registered for use over TCP and TLS and the other dissector being registered for use over packet protocols. This mechanism, unlike the other mechanisms, is not dependent on information in the packet_info structure that might be affected by dissectors other than the one for the protocol that transports protocol B. Furthermore, in a LINKTYPE_WIRESHARK_UPPER_PDU pcap or pcapng packet for protocol B, there might not be any information to indicate the protocol that transports protocol B, so there would have to be separate dissectors for protocol B, with separate names, so that a tag giving the protocol name would differ for B-over-byte-stream and B-over-packets. So: We rename EXP_PDU_TAG_PROTO_NAME and EXP_PDU_TAG_HEUR_PROTO_NAME to EXP_PDU_TAG_DISSECTOR_NAME and EXP_PDU_TAG_HEUR_DISSECTOR_NAME, to emphasize that they are *not* protocol names, they are dissector names (which has always been the case - if there's a protocol with that name, but no dissector with that name, Wireshark will not be able to handle the packet, as it will try to look up a dissector given that name and fail). We fix that exported PDU dissector to refer to those tags as dissector names, not protocol names. We update documentation to refer to them as DISSECTOR_NAME tags, not PROTO_NAME tags. (If there is any documentation for this outside the Wireshark source, it should be updated as well.) We add comments for calls to dissector_handle_get_dissector_name() where the dissector name is shown to the user, to indicate that it might be that the protocol name should be used. We update the TLS and DTLS dissectors to show the encapsulated protocol as the string returned by dissector_handle_get_long_name(); as the default is "Application Data", it appeaers that a descriptive name, rather than a short API name, should be used. (We continue to use the dissector name in debugging messages, to indicate which dissector was called.)
2022-09-08Qt+extcap: Make our capture error dialog less noisy.Gerald Combs1-0/+1
Strip the timestamps and function names from extcap errors before displaying them in a dialog. This keeps us from spewing ``` Error by extcap pipe: ** (falcodump:24913) 15:08:20.263535 [falcodump WARNING] extcap/falcodump.cpp:593 -- main(): cloudtrail plugin error: failed to list objects: ExpiredToken: The provided token has expired. status code: 400, request id: M2PYJOT4JGVAA6B9, host id: +4V8Q+DGV+80Jd3fdc7tODyVdTRvepNgCD9zuvXeL7kzvp2oikaoi9CLMW+UKt/ aR1G2UXIqyQ8= ``` at the user. Check for warning messages and set our dialog type accordingly.
2022-08-16win32-utils: Explicitly list inherited handlesTomasz Moń3-9/+71
Windows processes inherit all inheritable handles when a new process is created using CreateProcess() with bInheritHandles set to TRUE. This can lead to undesired object lifetime extension. That is, the child process will keep ineritable handles alive even if it does not use them. Up to Windows Vista it was not possible explicitly list handles that should be inherited. Wireshark no longer works on Windows releases earlier than Vista, so use the new API without checking Windows version. Require all callers to win32_create_process() to pass in the list of handles to inherit. Set the listed handles as inheritable shortly before calling CreateProcess() and set them as not inheritable shortly after the process is created. This minimizes possibility for other callers (especially in 3rd party libraries) to inherit handles by accident. Do not terminate mmdbresolve process on exit. Instead rely on process exit when EOF is received on standard input. Previously the EOF was never received because mmdbresolve inherited both ends of standard input pipe, i.e. the fact that Wireshark closed the write end was not observed by mmdbresolve because mmdbresolve kept write handle the standard input pipe open.
2022-08-14wsutil: Remove flawed ws_pipe_close() functionTomasz Moń2-17/+0
The semantics behind ws_pipe_close() were broken since its introduction. Forcing process termination on Windows, while simply setting variable on other systems results in more OS specific code sprinkled all over the place instead of less. Moreover ws_pipe_close() never handled standard file handles. It is really hard to come up with sensible ws_pipe_close() replacement, as process exit is actually asynchronous action. It is recommended to register child watch using g_child_watch_add() instead. Do not call ws_pipe_close() when deleting capture interface. Things will break if extcap is still running when interface opts are being freed and terminating process won't help. Rework maxmind shutdown to rely on GIOChannel state. For unknown reason TerminateProcess() is still needed on Windows. The actual root cause should be identified and fixed instead of giving up hope that it will ever work correctly on Windows. In other words, TerminateProcess() should not be used as a pattern, but rather as a last resort.
2022-08-10wsutil: Use GIOChannel for standard pipesTomasz Moń2-146/+31
Remove ws_read_string_from_pipe() as this function encourages bad design and is no longer necessary. Extcap stderr is read only after the child process has finished and thus the read will never block. Close process information thread handle right away as we don't use it. Remove unused ws_pipe_t member variables.
2022-08-03About: Reformat and expand some text.João Valverde4-75/+0
2022-07-27Convert capture file regex search to PCRE2.João Valverde2-12/+51
Replace the use of the obsolete GRegex with PCRE2. Fixes a crash reported in issue #17500.
2022-07-16Win32: Fix child process pipe handle leaksTomasz Moń1-0/+15
Close pipe handles when spawning asynchronous processes, so only the child process holds handle to the other end of the pipe. Closing the handles makes it possible to use pipes the same way as on other OS, that is to rely on blocking read() to end when child process finishes. Do not call CloseHandle() on signal pipe in capture sync after the handle ownership was transferred to file descriptor. Close the file descriptor instead.
2022-07-10Get CPU type strings from the OS if possible.Guy Harris1-5/+425
Instead of using an OS-independent and (somewhat) toolchain-independent, but x86-only, mechanism to fetch a string that identifies the type(s) of CPU on the machine, use OS-dependent but instruction-set-independent mechanisms. That way, we can get CPU type strings for non-x86 processors - ARM processors, in particular, but others as well (yes, you can run Wireshark on an IBM mainframe...). Fixes #18187.
2022-07-06Add a default configuration profile for Logray.Gerald Combs2-0/+12
Add and install default coloring rules and filter buttons for Logray. Add is_packet_configuration_namespace() and use it to set the default timestamp type for Logray to "Absolute", which is more appropriate for log entries.
2022-07-06Rename Logwolf to LograyGerald Combs2-10/+10
Switch to the name "Logray" for the log analyzer. Rays are biological cousins of sharks and more people like the name "Logray" in a completely unscientific survey here. Apologies for any inconvenience this might cause.
2022-06-21dfilter: Add support for literal strings with null bytesJoão Valverde8-101/+174
Before: Filter: frame matches "abc\x00def" dftest: \x00 (NUL byte) cannot be used with a regular string. frame matches "abc\x00def" ^~~~ Filter: _ws.ftypes.string == "a string with a \0 byte" dftest: \0 (NUL byte) cannot be used with a regular string. _ws.ftypes.string == "a string with a \0 byte" ^~ After: Filter: frame matches "abc\x00def" Syntax tree: 0 TEST_MATCHES: 1 FIELD(frame) 1 PCRE(abc\0def) Instructions: 00000 READ_TREE frame -> reg#0 00001 IF_FALSE_GOTO 3 00002 ANY_MATCHES reg#0 matches abc\0def 00003 RETURN Filter: _ws.ftypes.string == "a string with a \0 byte" Syntax tree: 0 TEST_ANY_EQ: 1 FIELD(_ws.ftypes.string) 1 FVALUE("a string with a \0 byte" <FT_STRING>) Instructions: 00000 READ_TREE _ws.ftypes.string -> reg#0 00001 IF_FALSE_GOTO 3 00002 ANY_EQ reg#0 == "a string with a \0 byte" <FT_STRING> 00003 RETURN Fixes issue #16156.
2022-06-21wsutil/str_util: Escape string API extensionsJoão Valverde3-50/+90
Allow to specify the length instead of requiring a null terminated string. Add a function to escape embedded null bytes in a counted string.