Commit Graph

1062 Commits

Author SHA1 Message Date
João Valverde 7b845e7194 wsutil: rename bytestring_to_str() -> bytes_to_str_punct() 2021-07-29 17:23:05 +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 8cf9791679 Replace some lingering references to g_log() 2021-06-19 02:34:36 +00:00
João Valverde 0e50979b3f Replace g_assert() with ws_assert() 2021-06-19 01:23:31 +00:00
João Valverde 39df3ae3c0 Replace g_log() calls with ws_log() 2021-06-16 12:50:27 +00:00
João Valverde 9ba97d12d6 Add ws_debug() and use it
Replace most instances of ws_debug_printf() except in
epan/dissectors and dissector plugins.

Some replacements use printf(), some use ws_debug(), and
some were removed because they were dead or judged to be
temporary.
2021-05-24 01:13:19 +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
Constantine Gavrilov 3a0e1ba1e2 NVMe: Increase PROTO_PRE_ALLOC_HF_FIELDS_MEM. 2021-04-19 07:14:51 +00:00
Constantine Gavrilov 5db4d2c0c9 Fix compilation with gcc-11.
Closes #17281
2021-04-17 10:29:15 +00:00
Guy Harris 512adcb046 ptvcursor: just do a realloc.
ptvcursor_new_subtree_levels() just needs to do a wmem_realloc() on the
subtree array; that will take care of ensuring the old data is in the
new array.
2021-04-16 08:34:54 +00:00
Simon Holesch fa483ac191 ptvcursor: Fix crash with deeply nested subtrees
If the proto tree is more than 8 levels deep, the subtree_lvl array
length is extended, by allocating a new area and copying everything into
that new area. However the old array length wasn't calculated correctly,
so only part of the subtree_lvl array was copied, causing a crash after
two ptvcursor_pop_subtree() calls.
2021-04-16 06:52:07 +00:00
Guy Harris b61fd6d76a dfilter, ftypes: get rid of FT_PCRE.
It's not a valid field type, it's only a hack to support regular
expression matching in packet-matching expressions.

Instead, in the packet-matching code, have a separate syntax tree type
for Perl-compatible regular expressions, and a separate instruction to
load one into a register, and have the "matching" operator for field
types take a GRegex * as the second argument.
2021-03-21 03:27:44 -07:00
Guy Harris 6ffbbcefa3 libwireshark: don't allow fields of type FT_PCRE to be registered.
It's a fake "field" type, used only for "field" values in
packet-matching expressions to do regular-expression matching.  There is
*no* reason to allow fields of that type.

Don't bother checking the representation type when generating the string
representation of a field value.  If a developer manages to get past all
the tests for FT_PCRE to register and add an instance of that field to
the protocol tree, either 1) the one and only string representation of
an FT_PCRE value is what they want, in which case, whatever, or 2) it's
*not* what they want, in which case, if they file a bug, ask a question
on a mailing list, or ask a question on the Q&A site, we can explain to
them that what they're doing is bogus.
2021-03-20 00:02:51 -07:00
Guy Harris a52ab28013 pcapng dissection: fix dissection of the if_filter IDB option.
Show the first octet of the option, giving the filter type.

Only display the rest of the option as a string if the type is 0,
meaning it's a libpcap-style filter string.

While we're at it, clean up the dissection of the rest of the options:

* do more proto_tree_add_item_ret_XXX to get the option value;
* don't bother constructing a string for the value if we don't have to;
* use proto_tree_add_item_ret_display_string for string values, so we
know they're printable.
2021-03-11 08:31:07 +00:00
Anders Broman 4131019969 proto.c: Use global var insted of environment var
WIRESHARK_ABORT_ON_TOO_MANY_ITEMS
Closes #17275
2021-03-08 15:12:56 +00:00
Nicolás Alvarez ebfbf958f6 Add ENC_TIME_NSECS timestamp encoding
Add a new timestamp encoding format ENC_TIME_NSECS, like ENC_TIME_SEC but
for nanosecond values. Needed for my work-in-progress dissector for Apple
push notifications.
2021-02-10 12:45:54 +00:00
João Valverde 89fee9321e Avoid exposing HAVE_PLUGINS in the public API
Instead *_register_plugin() is turned into a noop (with a warning).

The test suit is failing with ENABLE_PLUGINS=Off (it was already failing
before and this patch didn't affect that).

Closes #17202.
2021-02-06 16:35:51 +00:00
João Valverde be0171019c UDP: Clean up handling of zero-valued UDP checksums
Replace the somewhat weird field format
    "[Checksum: [missing]]"
with
    "Checksum: 0x0000 [ignored or illegal value]"

Improve code redability and fix XXX comment.
2021-01-27 16:46:15 +00:00
Dario Lombardo 41a4d594b9
proto: replace g_assert_not_reached() with REPORT_DISSECTOR_BUG().
Instead of giving a stack trace when the caller passed bad params,
raise a dissector bug, telling what the callee sees. This should
result in a better user experience.

Simplify code where possible.

Keep glib assertion for dead code due to compiler complains.
2021-01-12 10:24:39 +01:00
Dario Lombardo cd30f2434e proto: report dissector bug in proto_item_add_bitmask_tree.
It's illegal to call this function without fields. If that happens
we are hitting a dissector bug: report it.

Fix: #17115.
2020-12-30 10:19:19 +00:00
Stig Bjørlykke 59e16ad039 Qt: Prevent multiple check marks in custom column
This was prevented before but was broken in g3a7966c7.
2020-12-04 17:16:15 +00:00
Gerald Combs a9fc769d7b epan: Fix a memory leak.
Make sure _proto_tree_add_bits_ret_val allocates a bits array using the
packet scope, otherwise we leak memory. Fixes #17032.
2020-12-02 16:02:20 +00:00
John Thacker 7654bb260d QT+epan: Set FI_BITS_OFFSET and FI_BITS_SIZE flags on [u]ints and bitmasks
Set the FI_BITS_OFFSET and FI_BITS_SIZE flags appropriately on [u]int[64]
(and thus chars and booleans) where the bitmask is passed in on the
header_field_info. Also set the flags on bitmask items by ORing the bitmasks
from the constituent fields. These flags are only used right now in the
packet diagram.

This makes the packet diagram display those types of fields correctly without
having to use proto_item_set_bits_offset_len(), so long as the bitmask is
correct and the field width of the type matches the octet length. (If it
doesn't match, that's a dissector bug.)

split bit items are a more complicated case and still not handled correctly.
2020-11-19 12:00:46 +00:00
Gerald Combs 3a7966c716 Qt+epan: Print better-looking values in the packet diagram.
Pull the value-formatting code in proto_custom_set into
proto_item_fill_display_label. Use that in FieldInformation::toString
instead of fvalue_to_string_repr. Fixes #16911.
2020-11-13 19:41:51 +00:00
John Thacker 524a28c4b1 QT/CLI: Move max tree items and depth to prefs
Move the maximum number of tree items and maximum tree depth to
preferences instead of hardcoded values. Refer to issue #12584 for
an example VNC capture where real data exceeds the current limit.
2020-10-23 04:18:36 +00:00
Filipe Laíns 0ceb46e1c2 proto: add support for FT_BYTES in proto_tree_add_bits
Change-Id: I5030d550bd760953ac84c2700bb0e03cc7a831a1
Signed-off-by: Filipe Laíns <lains@archlinux.org>
2020-10-15 18:21:34 +00:00
Guy Harris 5dd6fc9459 Add proto_tree_add_item_ret_ipv4().
Change some guint32's to ws_in4_addr while we're at it.
2020-10-11 17:54:58 -07:00
Guy Harris 41c7b848d0 Fix some error messages. 2020-10-11 13:46:02 -07:00
Guy Harris c597927da8 Add some more string encodings.
Add an encoding for "unpacked" 3GPP TS 23.038 7-bit strings, in which
each code position is in a byte of its own, rather than with the code
positions packed into 7 bits.  Rename the packed encoding to explicitly
indicate that it's packed.

Add an encoding for ETSI TS 102 221 Annex A strings.

Use the new encodings.
2020-09-28 22:30:35 +00:00
Guy Harris 272502790b Add FT_STRINGZTRUNC.
FT_STRINGZPAD is for null-*padded* strings, where the field is in an
area of specified length, and, if the string is shorter than that
length, all bytes past the end of the string are NULs.

FT_STRINGZTRUNC is for null-*truncated* strings, where the field is in
an area of specified length and, if the string is shorter than that
length, there's a null character (which might be more than one byte, for
UCS-2, UTF-16, or UTF-32), and anything after that is not guaranteed to
have any particular value.

Use IS_FT_STRING() in some places rather than enumerating all the string
types, so that those places get automatically changed if the set of
string types changes.
2020-09-12 14:16:12 -07:00
Pascal Quantin cb810e7003 proto.c: add support for BASE_SPECIAL_VALS to fill_label_number64()
This is similar to what is done in fill_label_number()
2020-09-11 03:12:07 +00:00
Pascal Quantin dfabf33dfd proto.c: increase PROTO_PRE_ALLOC_HF_FIELDS_MEM 2020-09-05 18:00:48 +02:00
Gerald Combs 97dcaf97fc Convert Gerrit URLs to GitLab.
Convert various code.wireshark.org URLs to their
gitlab.com/wireshark/wireshark equivalents.

Change-Id: I0150d1bd14208eb451a7de818dce6573363b1d27
2020-08-24 23:31:32 +00:00
Guy Harris a42286524a Only do trailing stray character checks on FT_STRING fields.
FT_STRINGZ means "terminated by a null character", so there can't be
non-null characters following the terminating null.

FT_STRINGZPAD doesn't only mean "padded with nulls"; there are protocols
where a string that's not the full length of the part of the packet for
the string has a null terminator but isn't guaranteed to be fully padded
with nulls.  We can later add a separate type for fields where we really
*should* check that the padding is all nulls.

Change-Id: I5964817b4b847cb4db73f8ac673141052e8ef92c
Reviewed-on: https://code.wireshark.org/review/38230
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-08-22 23:12:08 +00:00
Guy Harris 9eddbdafa9 Don't give a zero-length FT_STRINGZ a special value.
It's arguably an error, as an FT_STRINGZ requires at least one character
position for the terminating NUL, but the way to handle that is to give
it a string value of an empty string and add an expert info indicating
that the terminating NUL is missing.  (The same should be done for
FT_STRINGZ fields with a specified non-zero length that don't have a NUL
in the last character position.)

Change-Id: Ie702bf44db36310f0f6e2625a3a64e6424167546
Reviewed-on: https://code.wireshark.org/review/38136
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-08-12 08:49:49 +00:00
Gerald Combs 9b07412277 Qt: Add a packet diagram view.
Add a new top-level view that shows each packet as a series of diagrams
similar to what you'd find in a networking textook or an RFC.

Add proto_item_set_bits_offset_len so that we can display some diagram
fields correctly.

Bugs / to do:
  - Make this a separate dialog instead of a main window view?
  - Handle bitfields / flags

Change-Id: Iba4897a5bf1dcd73929dde6210d5483cf07f54df
Reviewed-on: https://code.wireshark.org/review/37497
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>
2020-08-10 18:17:50 +00:00
Pascal Quantin fcd7492566 proto.c: increase PROTO_PRE_ALLOC_HF_FIELDS_MEM
Change-Id: I68a971b9a299d85007f4b7f436750515a8dfe7fa
Reviewed-on: https://code.wireshark.org/review/38101
Reviewed-by: Pascal Quantin <pascal@wireshark.org>
2020-08-09 21:37:23 +00:00
Guy Harris 2261b59eae Replace more DISSECTOR_ASSERT_NOT_REACHED() with more specific messages.
Have the message indicate the problem and the name of the offending field.

Change-Id: I661125814c9ad5585a3e71d14f8407948e2e6d76
Reviewed-on: https://code.wireshark.org/review/38090
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-08-09 08:09:27 +00:00
Moshe Kaplan 3b47a55b0d Replace instances of wmem_alloc with wmem_new
This commit replaces instances of
  (myobj *)wmem_alloc(wmem_X_scope(), sizeof(myobj))
and replaces them with:
  wmem_new(wmem_X_scope(), myobj)
to improve the readability of Wireshark's code.

Replacements were made with the following Python script:

import os
import re
import sys

pattern = r'\(([^\s\n]+) ?\*\) ?wmem_alloc(0?)\((wmem_[a-z]+_scope\(\)), sizeof\(\1\)\)'
replacewith = r'wmem_new\2(\3, \1)'

startdir = sys.argv[1]

for root, dirs, files in os.walk(startdir):
    for fname in files:
        fpath = os.path.join(root, fname)
        if not fpath.endswith('.c'):
            continue
        with open(fpath, 'r') as fh:
            fdata = fh.read()
        output = re.sub(pattern, replacewith, fdata)
        if fdata != output:
            print(fpath)
            with open(fpath, 'w') as fh:
                fh.write(output)

Change-Id: I223cb2fcce336bc99ca21c4a74e4cf758fd00572
Reviewed-on: https://code.wireshark.org/review/38088
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-08-08 09:54:29 +00:00
Martin Mathieson ccd7e1a63a ptvcursor_add_ret_int(): Fix error string if item of wrong type
Change-Id: I4bcfbc41d49f8e530893cd52d04d1ac6f9cc8494
Reviewed-on: https://code.wireshark.org/review/38013
Petri-Dish: Martin Mathieson <martin.r.mathieson@googlemail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Martin Mathieson <martin.r.mathieson@googlemail.com>
2020-08-01 13:01:00 +00:00
Gerald Combs 30f8f9656b epan: Fixup our ENABLE_CHECK_FILTER warnings.
Make sure we use g_warning to print each ENABLE_CHECK_FILTER warning.
g_warning automatically appends a newline, so there's no need for us to
do so.

Change-Id: I4ddb60f0e3e0382fb3ca6e996ad47410fe05d8be
Reviewed-on: https://code.wireshark.org/review/37748
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
2020-07-06 18:42:07 +00:00
Guy Harris e1d9a226a2 Fix the type of arrays of pointers to hf_ values for bitfield routines.
The static arrays are supposed to be arrays of const pointers to int,
not arrays of non-const pointers to const int.

Fixing that means some bugs (scribbling on what's *supposed* to be a
const array) will be caught (see packet-ieee80211-radiotap.c for
examples, the first of which inspired this change and the second of
which was discovered while testing compiles with this change), and
removes the need for some annoying casts.

Also make some of those arrays static while we're at it.

Update documentation and dissector-generator tools.

Change-Id: I789da5fc60aadc15797cefecfd9a9fbe9a130ccc
Reviewed-on: https://code.wireshark.org/review/37517
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-06-19 11:32:26 +00:00
Guy Harris 67e70dcad2 proto: clean up comments.
Say "attempt to XXX", as the attempt might not succeed.

Fix a copied-and-pasted comment to reflect what
proto_is_frame_protocol() does.

Change-Id: Ia16a98064b87001f019fda43f2db2970a89e355e
Reviewed-on: https://code.wireshark.org/review/37486
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-06-16 08:34:03 +00:00
Uli Heilmeier 66d5bb9dbe proto.c: check for proto_item_get_display_repr()
Check if proto item exists

Bug: 16592
Change-Id: Ida6950e94dfee935e448198df6199e96b1140aa2
Reviewed-on: https://code.wireshark.org/review/37350
Petri-Dish: Jaap Keuter <jaap.keuter@xs4all.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Jaap Keuter <jaap.keuter@xs4all.nl>
2020-06-06 14:51:22 +00:00
Guy Harris 9f03cde5a5 Add a routine to get the representation of a protocol tree item and use it.
Add proto_item_get_display_repr(), which returns a string, allocated
with a specified wmem scope, containing the display representation of
the value of a proto_item.

Use it in the LLDP dissector, to append that string to the parent
protocol tree item; use packet scope, so it doesn't hang around forever
(the previous code used the NULL scope, meaning explicit freeing was
required, but it wasn't explicitly freeing the value, so it was
leaking).

Change-Id: I146380118833b1daef9dea8bd9463001e5b9325f
Reviewed-on: https://code.wireshark.org/review/36931
Petri-Dish: Guy Harris <gharris@sonic.net>
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-04-25 06:27:53 +00:00
Jaap Keuter 9750d00ff1 Introduce tfs_get_string helper
true_false_strings have no helper function to properly retrieve the
string representing the true or false value, much like unit_strings,
even though this is not uncommon in dissectors.
This change introduces the helper function and modifies the dissectors,
so that they use this helper i.s.o. their own expressions.

Change-Id: I477ed2d90a9a529fc5dcfef7e3ea42ec180d27ae
Reviewed-on: https://code.wireshark.org/review/36920
Reviewed-by: Jaap Keuter <jaap.keuter@xs4all.nl>
Petri-Dish: Jaap Keuter <jaap.keuter@xs4all.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-04-25 04:39:46 +00:00
Martin Kaiser 55d3d32239 proto: remove a temporary variable
In proto_tree_add_item_ret_time_string, we should return the result of
proto_tree_add_node directly like other similar functions.

Change-Id: I5f0cdc32ee3e69ecf3c62f1d56cb8278c91c9c45
Reviewed-on: https://code.wireshark.org/review/36716
Reviewed-by: Martin Kaiser <wireshark@kaiser.cx>
Petri-Dish: Martin Kaiser <wireshark@kaiser.cx>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-04-05 18:22:35 +00:00
Martin Mathieson ec781e9749 proto: Add a debug check to sanity-check range_string
Check is enabled by #ifdef ENABLE_CHECK_FILTER
Remaining issues found by this check are fixed here,
along with a documentation note that the entries
are checked in order and the first match is used.

The only issue not yet fixed is in packet-isup.c,
where the spec was not available to me.

Change-Id: Ife747cda9b91a265bc2b81ce0a53f55f3389919e
Reviewed-on: https://code.wireshark.org/review/36708
Petri-Dish: Martin Mathieson <martin.r.mathieson@googlemail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Martin Mathieson <martin.r.mathieson@googlemail.com>
2020-04-05 17:40:21 +00:00
Dario Lombardo 3885912cca proto: fix invalid types in hf check routine.
The conditional code compiles with ENABLE_CHECKHF_CONFLICT=1.
The mix of string_value and string_value64 requires to split
up the code, and a macro seems to be the most suitable solution
since types are involved.

The error raises on Ubuntu 18.04:

FAILED: epan/CMakeFiles/epan.dir/proto.c.o
/usr/bin/cc -DG_DISABLE_DEPRECATED -DG_DISABLE_SINGLE_INCLUDES -DWS_BUILD_DLL -Depan_EXPORTS -I. -I../ -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/lua5.2 -I/usr/include/libxml2 -Iepan -I../epan -fvisibility=hidden  -fexcess-precision=fast -Wall -Wextra -Wendif-labels -Wpointer-arith -Wformat-security -fwrapv -fno-strict-overflow -Wvla -Waddress -Wattributes -Wdiv-by-zero -Wignored-qualifiers -Wpragmas -Wno-overlength-strings -Wno-long-long -Wframe-larger-than=32768 -Wc++-compat -Wunused-const-variable -Wshadow -Wold-style-definition -Wstrict-prototypes -Wlogical-op -Wjump-misses-init -Werror=implicit -Wno-pointer-sign -std=gnu99  -O2 -g -DNDEBUG -fPIC   -isystem /usr/include/mit-krb5 -Werror -MD -MT epan/CMakeFiles/epan.dir/proto.c.o -MF epan/CMakeFiles/epan.dir/proto.c.o.d -o epan/CMakeFiles/epan.dir/proto.c.o   -c ../epan/proto.c
../epan/proto.c: In function ‘tmp_fld_check_assert’:
../epan/proto.c:8013:18: error: assignment from incompatible pointer type [-Werror=incompatible-pointer-types]
     start_values = VAL64_STRING_EXT_VS_P(((const val64_string_ext*)hfinfo->strings));
                  ^
cc1: all warnings being treated as errors
[27/388] Building CXX object ui/qt/CMakeFiles/qtui.dir/coloring_rules_dialog.cpp.o
ninja: build stopped: subcommand failed.

Change-Id: I77c424bac96a1bbe81c0826faef66df7cc476ec4
Reviewed-on: https://code.wireshark.org/review/36604
Reviewed-by: Martin Mathieson <martin.r.mathieson@googlemail.com>
Petri-Dish: Martin Mathieson <martin.r.mathieson@googlemail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-04-02 07:47:23 +00:00
Martin Mathieson 71e9009825 Check for true_false_string with identical true/false string.
Fixed a few instances where fix were obvious, others are
less clear.
The check in proto.c is protected by ENABLE_CHECK_FILTER.

Change-Id: I4edee4e67bd53bbf2eb809d68c87983a7c5a66f3
Reviewed-on: https://code.wireshark.org/review/36645
Reviewed-by: Martin Mathieson <martin.r.mathieson@googlemail.com>
2020-04-01 10:32:08 +00:00