Commit Graph

34 Commits

Author SHA1 Message Date
João Valverde a0d77e9329 dfilter: Return an error object instead of string
Return an struct containing error information. This simplifies
the interface to more easily provide richer diagnostics in the future.

Add an error code besides a human-readable error string to allow
checking programmatically for errors in a robust manner. Currently
there is only a generic error code, it is expected to increase
in the future.

Move error location information to the struct. Change callers and
implementation to use the new interface.
2022-11-28 15:46:44 +00:00
Gerald Combs 70bd130379 Fix "generated by" comments in configuration files.
Add get_configuration_namespace() and use it in code that writes
"generated by" comments at the top of various configuration files.

Update our Logwolf colorfilters.
2022-04-29 18:00:21 +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 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
Moshe Kaplan e16166a74c Detect and replace bad allocation patterns
Adds a pre-commit hook for detecting and replacing
occurrences of `g_malloc()` and `wmem_alloc()` with
`g_new()` and `wmem_new()`, to improve the
readability of Wireshark's code, and
occurrences of
`g_malloc(sizeof(struct myobj) * foo)`
with
`g_new(struct myobj, foo)`
to prevent integer overflows

Also fixes all existing occurrences across
the codebase.
2020-12-22 14:56:38 +00:00
rbroker 1f75d7b3b9 wslua: Add ability to query current temporary color filter text
The LUA API provides the "set_color_filter_slot" function, but without
a corresponding "get_" function, it's very hard for two LUA dissectors
to co-exist without one overwriting any color filters set by the other.

It also looks like the documentation comment for
"set_color_filter_slot" had an off-by-one error, which I've corrected
as I was adding almost identical documentation for the new API.

Change-Id: Ic54d23be555ec12e1830bbe6f84a1b04d04fd4f0
Reviewed-on: https://code.wireshark.org/review/37511
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-06-25 08:02:27 +00:00
Martin Mathieson e0eefe186a Fix some cppcheck issues:
- Some redundant assignments or tests.
- Some declarations were changed to match definitions in terms of
including _U_ for the same parameters
- Some parenthesis added/changed to made precedence more obvious

epan/color_filters.c:533: style: Variable 'name' is reassigned a value before the old one has been used.
epan/color_filters.c:534: style: Variable 'filter_exp' is reassigned a value before the old one has been used.
asn1/tcap/packet-tcap-template.c:2199: warning: Function 'dissect_tcap_ITU_ComponentPDU' argument order different: declaration '_U_, tvb, offset, _U_, tree, _U_' definition '_U_, tvb, offset, actx, tree, _U_'
epan/dissectors/packet-aim.c:2546: warning: Function 'dissect_aim_tlv_value_icq' argument order different: declaration 'ti, subtype, tvb, _U_' definition 'ti, _U_, tvb, pinfo'
epan/dissectors/packet-arp.c:1133: style: Clarify calculation precedence for '&' and '?'.
epan/dissectors/packet-arp.c:1143: style: Clarify calculation precedence for '&' and '?'.
epan/dissectors/packet-arp.c:1158: style: Clarify calculation precedence for '&' and '?'.
epan/dissectors/packet-arp.c:1168: style: Clarify calculation precedence for '&' and '?'.
epan/dissectors/packet-gtpv2.c:5997: warning: Function 'dissect_gtpv2_mbms_service_area' argument order different: declaration 'tvb, _U_, tree, _U_, _U_, _U_, _U_, _U_' definition 'tvb, _U_, tree, item, _U_, _U_, _U_, _U_'
epan/dissectors/packet-gtpv2.c:6291: warning: Function 'dissect_gtpv2_mbms_time_to_data_xfer' argument order different: declaration 'tvb, _U_, tree, _U_, _U_, _U_, _U_, _U_' definition 'tvb, _U_, tree, item, _U_, _U_, _U_, _U_'
epan/dissectors/packet-gtpv2.c:6369: warning: Function 'dissect_gtpv2_epc_timer' argument order different: declaration 'tvb, _U_, tree, _U_, _U_, _U_, _U_, _U_' definition 'tvb, _U_, tree, item, _U_, message_type, _U_, _U_'
epan/dissectors/packet-knxip.c:2939: style: Condition 'mac_error' is always false  (just added comment)
epan/dissectors/packet-mac-lte.c:4386: style: Clarify calculation precedence for '&' and '?'.
epan/dissectors/packet-nas_5gs.c:1828: style: Variable 'nas5gs_data->payload_container_type' is reassigned a value before the old one has been used. (noted confusing recursion)
epan/dissectors/packet-rpcrdma.c:587: warning: Identical condition 'offset>max_offset', second condition is always false
epan/dissectors/packet-rsl.c:2098: style: Assignment of function parameter has no effect outside the function.

Change-Id: Ib5c9a04cfb6e6233972bc041434601c8ef09c969
Reviewed-on: https://code.wireshark.org/review/37343
Petri-Dish: Martin Mathieson <martin.r.mathieson@googlemail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Martin Mathieson <martin.r.mathieson@googlemail.com>
2020-06-01 20:44:27 +00:00
Guy Harris 95073e299c epan/color filters: plug a memory leak.
Change-Id: Ibda5266e6b6a612cf7add319dcb8e3da93b57da0
Ping-Bug: 16335
Reviewed-on: https://code.wireshark.org/review/37038
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-05-02 23:05:25 +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
Dario Lombardo 9aa63d2406 epan: remove return from functions returning void.
Found by clang-tidy.

Change-Id: Ibedfec5e5d3eca7c2e65319b7ecb4dcbe974b88b
Reviewed-on: https://code.wireshark.org/review/31337
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-01-04 05:07:58 +00:00
Stig Bjørlykke e1fc60ddae Qt: Add back pathLabel in some dialogs
Add the pathLabel for Coloring Rules, Decode As, Display Filters
and Capture Filter. Put the absolute file path into the pathLabel
if the file exists. This aligns with UAT dialogs and frames.

Change-Id: I72bd06e31bab220de0a0ef8df99df9a4daed667c
Reviewed-on: https://code.wireshark.org/review/30089
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-10-10 04:46:28 +00:00
Stig Bjørlykke b0dd361d48 prefs: Don't remove unknown coloring rules.
When saving the colorfilters file, keep and disable unknown coloring
rules instead of removing them. The user may want to correct the syntax.

Change-Id: Ib27612a0601276b6ebbb467d7d253f3f72103d1c
Reviewed-on: https://code.wireshark.org/review/29908
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2018-09-29 10:27:01 +00:00
Stig Bjørlykke e804e63d4d prefs: Reset prefs.unknown_colorfilters before reading colorfilters
Reset prefs.unknown_colorfilters in the beginning of read_filters_file()
to avoid a situation when the preference is set and never cleared.
This will end up with an error message in UI even when not having
unknown color filters.

Change-Id: I835dbc2a57f0be6889eb5bce250987dabd796e30
Reviewed-on: https://code.wireshark.org/review/29904
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2018-09-29 10:18:16 +00:00
Gerald Combs 8f08a4e74e Try to discourage the use of APIs via counting.
Add the ability to specify maximum function counts for each group to
checkAPIs. Add maximum counts for the "termoutput" and "abort" groups
where needed. Show summaries in various checkAPI targets.

Switch uses of ws_g_warning back to plain g_warning.

Change-Id: I5cbddc8c671729e424eed8551f69116d16491976
Reviewed-on: https://code.wireshark.org/review/29721
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2018-09-19 16:07:03 +00:00
Anders 25a337cdb0 glib: Use g_slist_free_full() in a couple of places.
Change-Id: Iff833bf5c197959c8decb62d6ce794c6d0415fb7
Reviewed-on: https://code.wireshark.org/review/26978
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-04-17 15:01:24 +00:00
Gerald Combs 1d030928ef Remove some GTK+-only code.
Change-Id: Ic2498c7acd6a1a522be45094148402ee34a6b4d1
Reviewed-on: https://code.wireshark.org/review/26958
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>
2018-04-17 03:44:47 +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
Jakub Zawadzki 4a417149d4 Fix memleak in color_filters_read_globals()
Valgrind log:

==6102== Thread 1:
==6102== 32 bytes in 1 blocks are definitely lost in loss record 24,851 of 49,782
==6102==    at 0x4C29C4F: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==6102==    by 0xB17B7F7: __vasprintf_chk (vasprintf_chk.c:80)
==6102==    by 0xA98C2AB: vasprintf (stdio2.h:210)
==6102==    by 0xA98C2AB: g_vasprintf (gprintf.c:316)
==6102==    by 0xA966DCC: g_strdup_vprintf (gstrfuncs.c:507)
==6102==    by 0xA966E88: g_strdup_printf (gstrfuncs.c:533)
==6102==    by 0x6A66B8C: color_filters_read_globals (color_filters.c:704)
==6102==    by 0x6A66FBE: color_filters_get (color_filters.c:317)
==6102==    by 0x402313: fuzz_init (fuzzshark.c:237)
==6102==    by 0x40252D: LLVMFuzzerInitialize (fuzzshark.c:322)
==6102==    by 0x401E33: main (StandaloneFuzzTargetMain.c:125)

Change-Id: Ibc18edff6097eca736328810c903a151ddee22bc
Reviewed-on: https://code.wireshark.org/review/25553
Tested-by: Jakub Zawadzki <darkjames-ws@darkjames.pl>
Petri-Dish: Jakub Zawadzki <darkjames-ws@darkjames.pl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Jakub Zawadzki <darkjames-ws@darkjames.pl>
2018-02-01 23:17:19 +00:00
Ahmad Fatoum 9d49e13166 Remove superfluous null-checks before strdup/free
NULL checks were removed for following free functions:

- g_free "If mem is NULL it simply returns"
  https://developer.gnome.org/glib/stable/glib-Memory-Allocation.html#g-free

- g_slist_free(_full)? "NULL is considered to be the empty list"
  https://developer.gnome.org/glib/stable/glib-Singly-Linked-Lists.html

- g_strfreev "If str_array is NULL, this function simply returns."
  https://developer.gnome.org/glib/stable/glib-String-Utility-Functions.html#g-strfreev

- g_slice_free "If mem is NULL, this macro does nothing."
  https://developer.gnome.org/glib/stable/glib-Memory-Slices.html#g-slice-free

- g_match_info_free "not NULL... otherwise does nothing"
  https://developer.gnome.org/glib/stable/glib-Perl-compatible-regular-expressions.html#g-match-info-free

- dfilter_free defined in Wireshark code. Returns early when passed NULL
  epan/dfilter/dfilter.c

They were also removed around calls to g_strdup where applicable:

- g_strdup "If str is NULL it returns NULL."
  https://developer.gnome.org/glib/stable/glib-String-Utility-Functions.html#g-strdup

Change-Id: Ie80c2db89bef531edc3aed7b7c9f654e1d654d04
Reviewed-on: https://code.wireshark.org/review/23406
Petri-Dish: Roland Knall <rknall@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: João Valverde <j@v6e.pt>
2017-10-15 12:38:51 +00:00
Guy Harris ad4e81fcf8 Handle filter open and read errors better.
If the user's color filter file exists but can't be opened, fail and
return a failure indication.

If it doesn't exist, just try reading the global color filter file.

If *that* exists but can't be opened, fail and return a failure
indication; if it doesn't exist, don't treat that as an error.

Change-Id: I5ebdc0eb1ada3cc190990be9228639304f32147e
Reviewed-on: https://code.wireshark.org/review/22054
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-06-09 22:05:05 +00:00
Guy Harris 4d2d423106 Rename routines to clarify what they do.
XXX_prime_with_YYY makes it a bit clearer than does XXX_prime_YYY that
we're not priming YYY, we're priming XXX *using* YYY.

Change-Id: I1686b8b5469bc0f0bd6db8551fb6301776a1b133
Reviewed-on: https://code.wireshark.org/review/21031
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-04-12 04:56:49 +00:00
Gerald Combs 6499a02395 Color filters: Initialize a variable.
Make sure temp_dfilter is initialized so that we don't end up freeing
invalid memory.

Change-Id: Id31969573690574846422b67c950188fd6ee4ef3
Reviewed-on: https://code.wireshark.org/review/18066
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2016-10-04 16:11:14 +00:00
Gerald Combs 1320ea4d57 Be more forgiving about invalid Coloring Rules.
In ColoringRulesDialog:

Only check a rule's display filter if that rule is enabled. This keeps
us from disabling the OK button when we shouldn't.

Adjust the "Your coloring rules file contains unknown rules" dialog text
and buttons for accuracy.

In color_filters.c:

Don't try to compile disabled filters in color_filters_apply. Don't warn
about disabled and invalid filters in read_filters_file.

Bug: 12814
Change-Id: I7143bf8e7a6162d296f1e93769344b69763195c8
Reviewed-on: https://code.wireshark.org/review/17823
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-10-03 17:47:39 +00:00
Guy Harris d430ba3014 Report the pathname of the color filter file in "Could not compile" messages.
This also fixes some cases where we wouldn't report the path in a read
error message, as we'd already freed the path up and set the path string
pointer to null.

Change-Id: Ia0e1ca0bf4880075bfa1957b0778a177de1a824f
Reviewed-on: https://code.wireshark.org/review/16868
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-08-04 02:04:34 +00:00
Gerald Combs e727ecf5e3 Don't discard unknown coloring rules.
When processing the colorfilters file, keep and disable unknown coloring
rules instead of skipping over and discarding them. This should
hopefully keep people from losing the standard "Checksum Errors" rule
(and it's less rude in general).

Change-Id: I21796c25045d9dbf7612238ce3d27b613f1ec75f
Reviewed-on: https://code.wireshark.org/review/16673
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-07-29 03:57:41 +00:00
Michael Mann 907d49483d Fix some of the checkAPIs.pl warnings for g_warning.
1. Create ws_g_warning for legitimate uses of g_warning
2. Use proto_tree_add_debug_text
3. Comment some out

Change-Id: Ida044bf40286b955fdd529c4f9907c8e09b3d7c5
Reviewed-on: https://code.wireshark.org/review/16678
Reviewed-by: Michael Mann <mmann78@netscape.net>
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-07-26 04:08:50 +00:00
Gerald Combs e2e84563ee Use getc_unlocked in a few places.
Use getc_unlocked or _fgetc_nolock instead of getc in a few places. This
reduces startup time by about 100ms here.

Change-Id: I59ceb09678457c871cce79fcc3ce71998fe4f5af
Reviewed-on: https://code.wireshark.org/review/14518
Reviewed-by: Michael Mann <mmann78@netscape.net>
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 16:18:25 +00:00
João Valverde 95dee44a77 const gpointer -> gconstpointer
'const gpointer' is the same as 'void *const'. Replace with gconstpointer
where straightforward (assuming that was the intent) and use gpointer everywhere
else for clarity (that does not change *API* constness contract; it just means
a variable is not declared immutable inside the called funtion).

Change-Id: Iad2ef13205bfb4ff0056b2bce056353b58942267
Reviewed-on: https://code.wireshark.org/review/13945
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2016-02-16 05:10:49 +00:00
João Valverde 47443b2b87 Fix warning for epan/color-filters.c -[-Wcast-qual]
Change-Id: I99ec380c844c597d397ec5d261d6bddac8d1999b
Reviewed-on: https://code.wireshark.org/review/13449
Reviewed-by: João Valverde <j@v6e.pt>
2016-01-21 15:23:35 +00:00
Michael Mann b344107d75 Make color filters part of dissection
Color filters can be seen as a function that takes a tree and display
filters as input and a (possibly empty) coloring rule as output.
This coloring rule is then added to the frame tree and used by the GUI
for coloring the packets list.

From an architectural POV, "coloring" is part of the UI component, but
since it influences the tree, it is something for the dissection
component.

Bug: 5703
Bug: 6099
Change-Id: I73d132ec1dca7262bcb1b55c8481ca564c6161d1
Reviewed-on: https://code.wireshark.org/review/12507
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-01-01 17:36:11 +00:00
Guy Harris f499265df7 Get rid of trailing whitespace.
Change-Id: If6347938525194c08465b9b383edf8fb7eaf1e49
Reviewed-on: https://code.wireshark.org/review/12986
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-01-01 04:18:06 +00:00
Guy Harris ee9f102aa9 No need for toolkit-dependent color initialization.
We're not allocating colors ourselves in GTK+ (and haven't been doing so
since at least 1.12), and all color_t values are valid colors, so
we don't need any toolkit-specific processing to fill in a color_t.

While we're at it, catch read errors when reading color filter files.

Change-Id: Ieb520d141cf15e371a31a01459d466c95ba2209b
Reviewed-on: https://code.wireshark.org/review/12985
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-01-01 04:15:29 +00:00
Michael Mann 5e4bbcda98 Refactor GUI dependencies out of color_filters.[ch] and move it to epan directory.
This also moved color.h into color_filters.h

Change-Id: Ic19e27aa1b3ec67e764aa7ee8bbef7b1187bb12e
Reviewed-on: https://code.wireshark.org/review/12831
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-12-28 18:33:41 +00:00