Commit Graph

994 Commits

Author SHA1 Message Date
Guy Harris a7256d50b5 wiretap: more work on file type/subtypes.
Provide a wiretap routine to get an array of all savable file
type/subtypes, sorted with pcap and pcapng at the top, followed by the
other types, sorted either by the name or the description.

Use that routine to list options for the -F flag for various commands

Rename wtap_get_savable_file_types_subtypes() to
wtap_get_savable_file_types_subtypes_for_file(), to indicate that it
provides an array of all file type/subtypes in which a given file can be
saved.  Have it sort all types, other than the default type/subtype and,
if there is one, the "other" type (both of which are put at the top), by
the name or the description.

Don't allow wtap_register_file_type_subtypes() to override any existing
registrations; have them always register a new type.  In that routine,
if there are any emply slots in the table, due to an entry being
unregistered, use it rather than allocating a new slot.

Don't allow unregistration of built-in types.

Rename the "dump open table" to the "file type/subtype table", as it has
entries for all types/subtypes, even if we can't write them.

Initialize that table in a routine that pre-allocates the GArray before
filling it with built-in types/subtypes, so it doesn't keep getting
reallocated.

Get rid of wtap_num_file_types_subtypes - it's just a copy of the size
of the GArray.

Don't have wtap_file_type_subtype_description() crash if handed an
file type/subtype that isn't a valid array index - just return NULL, as
we do with wtap_file_type_subtype_name().

In wtap_name_to_file_type_subtype(), don't use WTAP_FILE_TYPE_SUBTYPE_
names for the backwards-compatibility names - map those names to the
current names, and then look them up.  This reduces the number of
uses of hardwired WTAP_FILE_TYPE_SUBTYPE_ values.

Clean up the type of wtap_module_count - it has no need to be a gulong.

Have built-in wiretap file handlers register names to be used for their
file type/subtypes, rather than building the table in init.lua.

Add a new Lua C function get_wtap_filetypes() to construct the
wtap_filetypes table, based on the registered names, and use it in
init.lua.

Add a #define WSLUA_INTERNAL_FUNCTION to register functions intended
only for internal use in init.lua, so they can be made available from
Lua without being documented.

Get rid of WTAP_NUM_FILE_TYPES_SUBTYPES - most code has no need to use
it, as it can just request arrays of types, and the space of
type/subtype codes can be sparse due to registration in any case, so
code has to be careful using it.

wtap_get_num_file_types_subtypes() is no longer used, so remove it.  It
returns the number of elements in the file type/subtype array, which is
not necessarily the name of known file type/subtypes, as there may have
been some deregistered types, and those types do *not* get removed from
the array, they just get cleared so that they're available for future
allocation (we don't want the indices of any registered types to changes
if another type is deregistered, as those indicates are the type/subtype
values, so we can't shrink the array).

Clean up white space and remove some comments that shouldn't have been
added.
2021-02-17 21:54:28 +00:00
Gerald Combs e99c9afce8 Be more strict about opening URLs.
In the proto tree, copy URLs instead of opening them.

In the export dialog, enable previews only if the advertised MIME type
*and* the contents of the file are plain text, GIF, JPEG, or PNG.

Add warnings to the wslua browser_open_url and browser_open_data_file
documentation.

Fixes #17232.
2021-02-15 08:47:57 +00:00
Gerald Combs 270c8ed746 CMake: Make sure system headers are treated as such.
Use target_include_directories instead of include_directories in a few
places as recommended at

https://cmake.org/cmake/help/latest/command/include_directories.html

Doing so lets us mark a bunch of dependency includes SYSTEM PRIVATE, in
particular LIBXML2_INCLUDE_DIRS. On macOS this keeps us from triggering
the nullability warnings described at

https://www.wireshark.org/lists/wireshark-dev/202004/msg00056.html

(This might also keep the Visual Studio code analyzer from complaining
about various Qt headers, but I haven't tested this.)
2021-02-15 08:31:08 +00:00
Guy Harris b8b3531883 wiretap: register most built-in file types from its module.
Remove most of the built-in file types from the table in
wiretap/file_access.c and, instead, have the file types register
themselves, using wtap_register_file_type_subtypes().

This reduces the source code changes needed to add a new file type from
three (add the handler, add the file type to the table in file_access.c,
add a #define for the file type in wiretap/wtap.h) to one (add the
handler).  (It also requires adding the handler's source file to
wiretap/CMakeLists.txt, but that's required in both cases.)

A few remain because the WTAP_FILE_TYPE_SUBTYPE_ #define is used
elsewhere; that needs to be fixed.

Fix the wiretap/CMakefile.txt file to scan k12text.l, as that now
contains a registration routine.  In the process, avoid scanning files
that don't implement a file type and won't ever have a registration
routine.

Add a Lua routine to fetch the total number of file types; we use that
in some code to construct the wtap_filetypes table, which we need to do
in order to continue to have all the values that used to come from the
WTAP_FILE_TYPE_SUBTYPE_ types.

While we're at it, add modelines to a file that lacked them.
2021-02-14 00:58:46 -08:00
Guy Harris 5b3c3d0682 WSDG: deprecate wtap_filetypes.
Recommend the use of wtap_name_to_file_type_subtype() to get filetype
values, unless you need to run on older versions of Wireshark that don't
have it.

Don't even *mention* wtap_filetypes in the documentation for the new
wtap_ routines, as, if you have those routines, you have
wtap_name_to_file_type_subtype(), because it's one of those routines.

Fix references to "nul" while we're at it - it's "nil" in Lua.

(That part of the WSDG - the Lua reference - is generated, so this
involves changing the source code implementing the Lua routines.)
2021-02-13 22:12:23 -08:00
Guy Harris 24acef0885 wiretap: file types have a name and a description.
The "short name" is really just the name, used to look it up.  The
"name" is really a description intended solely for human consumption.
Rename the fields, and the functions that access them, to match.

The "description" maintained by Lua for file type handlers is used
*only* for one debugging message; we should probably just eliminate it.
Call it an "internal description" for now.
2021-02-13 01:25:39 -08:00
Guy Harris f0ebc50762 wslua: expose some libwiretap APIs in Lua.
Provide Lua version of wtap_file_type_subtype_string(),
wtap_file_type_subtype_short_string(), and
wtap_short_string_to_file_type_subtype().

This will be backported to the 3.2 and 3.4 branches, to allow scripts
not run on the bleeding-edge version to use them.
2021-02-12 21:25:29 -08:00
Guy Harris 23467afdc5 wslua: explain, in a comment, how .init routines work for a Proto. 2021-02-05 22:02:54 -08: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
Stig Bjørlykke 9cafd342ac Lua: Add get_preference() and set_preference() utility functions.
Support uint, bool, enum, string, range, filename and directory preferences.
Added apply_preferences() to write to file and apply changes.
2020-12-08 22:56:50 +00:00
George Powers e7ec6739b6 Fix reported_len in Lua framewark when creating tvb from range.
This bug affects Lua plugin dissectors for encapsulation protocols like
GRE.  Typically the dissector creates a range for the payload packet, then
calls the next dissector with a tvb derived from the range, using
TvbRange_tvb().  The original version calls
tvb_new_subset_length_caplen() using the remaining capture length for the
reported_len argument.  The fix passes -1 as the reported length, and
tvb_new_subset_length_caplen() calculates the new reported_len as required.

The bug only affects large packets captured with a snaplen and
truncated, then decoded with a Lua plugin for the encapsulation header.

Here's the typical bug symptom, gleaned from tshark decode of
an encapsulated IP payload:

        [Expert Info (Error/Protocol): IPv4 total length exceeds packet length (114 bytes)]
            [IPv4 total length exceeds packet length (114 bytes)]

Closes #15655.
2020-12-06 12:38:46 +00:00
Stig Bjørlykke d104571e8a Lua: Improve Listener error handling
Fix error handlers in Listener draw() and reset() to avoid getting
LUA_ERRERR from lua_pcall(). Added error handler for Listener draw()
callback.

Handle LUA_ERRERR from lua_pcall() to avoid assert on this.
Changed some capitalized words in various error message.

Closes #16974.
2020-12-04 13:38:00 +00:00
David Perry 27c00ca0e9 Lua: make TvbRange:raw() return a subset #12046 v2
My initial fix caused several double-offset errors in TvbRange_raw()
because I was adjusting for the TvbRange's offset too early in the
process. The proper fix is to only adjust for it in the final call to
get the data.

I also simplified some of the bounds checks to be based on the values in
the TvbRange instead of calling `tvb_captured_length()` and the like,
because its bounds are already checked against the backing Tvb when it's
first taken.

Massively expanded the lua test suite to account for every combination
of passing offsets and lengths to a Tvb or TvbRange and to the
subsequent `:raw()` call.
2020-12-02 20:09:55 +00:00
John Thacker 15d315c2ae GLib: Bump requirement 2.32 -> 2.36 2020-11-25 06:25:38 +00:00
Stig Bjørlykke ebfa1f8a4b wslua: Return nil from Dissector.get() when not found
Return nil from Dissector.get() and DissectorTable.get() when the
reference is not found. This can be used to check for existence of
a dissector or dissector table before use.

We already do this for DissectorTable.get_dissector().
2020-11-05 06:23:24 +00:00
Stig Bjørlykke 10e6cb5f37 wslua: Make pinfo.p2p_dir writable
Make pinfo.p2p_dir writeble from Lua to be able to set the direction
for sub-dissectors.
2020-10-22 14:18:58 +00:00
David Perry c03011b906 Lua: base64_decode: handle unpadded data
As noted in bug #16386, glib's `g_base64_decode_inplace()` aborts
decoding of base64 strings that aren't padded. This addresses that by
adding padding "=" characters if needed to the buffer which will be
decoded.

I added the test case from the bug report to the test suite, though the
location therein may not be ideal.

Closes #16386
2020-10-19 08:38:31 +00:00
Guy Harris 6e6233521a Have WTAP_ERR_INTERNAL include an err_info string giving details.
That way, users won't just see "You got an internal error", the details
will be given, so they can report them in a bug.
2020-10-14 04:51:45 +00:00
Guy Harris 7b5b6501f0 Revert "No need for a local lua_State * variable in file handler routines."
This reverts commit 873e079659.

That change didn't help what I wanted to do; there's another way to do
it.
2020-10-13 17:54:50 -07:00
Guy Harris 873e079659 No need for a local lua_State * variable in file handler routines.
Just use fh->L; the compiler will put that into a register if
appropriate.  This removes one side-effect from
INIT_FILEHANDLER_ROUTINE().
2020-10-13 13:30:52 -07:00
Guy Harris e013c5ec7f Clean up URLs.
Add ui/urls.h to define some URLs on various of our websites.  Use the
GitLab URL for the wiki.  Add a macro to generate wiki URLs.

Update wiki URLs in comments etc.

Use the #defined URL for the docs page in
WelcomePage::on_helpLabel_clicked; that removes the last user of
topic_online_url(), so get rid of it and swallow it up into
topic_action_url().
2020-10-02 20:13:42 -07:00
Chuck Craft 4a0d8d4ef6 Qt: point to Lua wiki page now on Gitlab 2020-10-02 17:25:54 +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
Gerald Combs 7ab6440416 Tools: Clean up checkAPI and add ui/qt.
Remove the --check-addtext and --build flags. They were used for
checkAddTextCalls, which was removed in e2735ecfdd.

Add the sources in ui/qt except for qcustomplot.{cpp,h}. Fix issues in
main.cpp, rtp_audio_stream.cpp, and wireshark_zip_helper.cpp.

Rename "index"es in packet-usb-hid.c.
2020-09-05 07:41:29 +00:00
Guy Harris 74e917fc6c wiretap: have wtap_dump_flush(), and its callers, check for errors.
Change-Id: Ibcddf1a949f775afa49d36a2d165c3685556035d
Reviewed-on: https://code.wireshark.org/review/38104
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-08-09 23:08:51 +00:00
Guy Harris 3a8111e1c2 Lua: give better errors for more WTAP_ERR_ types from wtap_dump_open().
Change-Id: I9878baebb78a36f306ae87b802680dc35875e862
Reviewed-on: https://code.wireshark.org/review/38041
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-08-04 09:36:08 +00:00
Gerald Combs bd11d5b90b wslua: Include stdint.h on Windows.
The Universal CRT supplies stdint.h, so there's no reason to define our
own types.

Change-Id: I40d4216136aaecae1dc07b0b32ac31032a74b632
Reviewed-on: https://code.wireshark.org/review/37648
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-07-01 20:23:22 +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
Gerald Combs da04d89f1e wslua: Update the ByteArray and Tvb docs.
Add content from https://wiki.wireshark.org/LuaAPI/ByteArray and
https://wiki.wireshark.org/LuaAPI/Tvb. Update as needed.

Remove an extraneous trailing semicolon.

Change-Id: I857b748821c21413ecb563c150525575fc9b947a
Reviewed-on: https://code.wireshark.org/review/36635
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-03-31 04:13:01 +00:00
Gerald Combs ed3fe162bd wslua: Update the Int64 docs.
Add content from https://wiki.wireshark.org/LuaAPI/Int64. Update as
needed.

Change-Id: I6a5f8c1cdeddee6d552fde940224704daca980b5
Reviewed-on: https://code.wireshark.org/review/36639
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-03-31 04:12:48 +00:00
Gerald Combs 99798d2c1c wslua: Update the Dir and Utils docs.
Add content from https://wiki.wireshark.org/LuaAPI/Utils. Update as
needed.

Change-Id: I2bf04d053a1edd5e05779c5a41e5ae0fbcb71b54
Reviewed-on: https://code.wireshark.org/review/36638
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-03-31 04:12:35 +00:00
Gerald Combs 6f59b8e84d wslua: Cross-reference and title case fixes.
Use lua_class_DissectorTable instead of lua_class_DissectorTables.

Use title case for each module.

Change-Id: Ie855022ee59a857c8ced7c3e6ba070ab494fa017
Reviewed-on: https://code.wireshark.org/review/36634
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2020-03-30 16:42:18 +00:00
Gerald Combs e53cb23b1f wslua: Update the packet information docs.
Add content from https://wiki.wireshark.org/LuaAPI/Pinfo and update as
needed.

Change-Id: Ia0b61b529c2a83d6dca8244916154cdc86289a79
Reviewed-on: https://code.wireshark.org/review/36628
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2020-03-30 16:08:37 +00:00
Gerald Combs 48407df448 wslua: Update the TreeItem docs.
Add content from https://wiki.wireshark.org/LuaAPI/TreeItem and update
as needed.

Change-Id: I59ae271bb6b77d3df1bf53e175a4eccbcf9049f6
Reviewed-on: https://code.wireshark.org/review/36630
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-03-30 08:55:42 +00:00
Gerald Combs 87be7fa23c wslua: Update the dissector docs.
Add content from https://wiki.wireshark.org/LuaAPI/Dissector,
https://wiki.wireshark.org/LuaAPI/Pref, and
https://wiki.wireshark.org/LuaAPI/Proto. Update as needed.

Change-Id: I74a167feb9db0fcdb723501e4692da020db1ab2c
Reviewed-on: https://code.wireshark.org/review/36629
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-03-30 08:55:19 +00:00
Gerald Combs 23a947073b wslua: Update the Listener docs.
Add content from https://wiki.wireshark.org/LuaAPI/Listener and update
as needed.

Add an example that dumps valid listener names.

Change-Id: I009eaa83c645b5ad78b560acb249a3060b2784ba
Reviewed-on: https://code.wireshark.org/review/36624
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-03-30 07:00:39 +00:00
Gerald Combs 1a3e64db39 wslua: Update the GUI docs.
Add content from https://wiki.wireshark.org/LuaAPI/GUI and update as
needed.

Separate some of our Asciidoctor output with newlines.

Change-Id: I2b8b9449c94bd69095fbd4b65ea415cd4d525c30
Reviewed-on: https://code.wireshark.org/review/36613
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-03-30 06:56:44 +00:00
Alexis La Goutte 9f5be6f7eb fix typo found by lintian (Uknown => Unknown)
Change-Id: I50ae0d1595cc42b3432f4611009c9c48b4cdde70
Reviewed-on: https://code.wireshark.org/review/36567
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2020-03-25 15:13:03 +00:00
Martin Mathieson eb439e89f1 wslua: WSLUA_BIT_OP_FUNC macro already does return .
epan/wslua/wslua_int64.c:445: style: Consecutive return, break, continue, goto or throw statements are unnecessary.
epan/wslua/wslua_int64.c:454: style: Consecutive return, break, continue, goto or throw statements are unnecessary.
epan/wslua/wslua_int64.c:463: style: Consecutive return, break, continue, goto or throw statements are unnecessary.
epan/wslua/wslua_int64.c:966: style: Consecutive return, break, continue, goto or throw statements are unnecessary.
epan/wslua/wslua_int64.c:975: style: Consecutive return, break, continue, goto or throw statements are unnecessary.
epan/wslua/wslua_int64.c:984: style: Consecutive return, break, continue, goto or throw statements are unnecessary.

Change-Id: I98d8c07cb13c523ba21469b7ad84ff4738764d49
Reviewed-on: https://code.wireshark.org/review/36556
Petri-Dish: Martin Mathieson <martin.r.mathieson@googlemail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Martin Mathieson <martin.r.mathieson@googlemail.com>
2020-03-24 12:59:27 +00:00
Moshe Kaplan 4a8da5fbde wslua: Fix crash on TvbRange:__tostring for a zero-length TVB
Fields such as 'frame.time_delta' have no byte selection, they are added
with offset 0 and length 0, and evidently 'ws_tvb' is NULL. As
tvb_bytes_to_str expects a non-NULL tvb, explicitly check for this and
add a dummy placeholder. This is intended to be a human-readable string,
so prefer `<EMPTY>` over an empty string.

Change-Id: I32efe4cbefc6bcf0fa9fb94fcf25d7bf1628f3a7
Reviewed-on: https://code.wireshark.org/review/36440
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2020-03-16 22:42:03 +00:00
Markku Leiniö 166c06ff15 Lua: Fix description for pinfo.dst_port
Change-Id: If0f6aeb357f0267cdf13763e7710ea221cc2600c
Reviewed-on: https://code.wireshark.org/review/36355
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2020-03-10 08:39:57 +00:00
Moshe Kaplan b7566bf40f LUA: remove duplicate words
Change-Id: Id3c5b1d7f67d8e4d3149ed6bdee7307bf13fda3d
Reviewed-on: https://code.wireshark.org/review/36263
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2020-03-03 07:37:30 +00:00
Gerald Combs d614ade782 De-camel-ize "Wireshark" in a few places.
The _wslua_main struct / WireShark class appears to have never been
used, so remove it.

Change-Id: Id80fb2c2065accedf632ea4cc467d566d10870de
Reviewed-on: https://code.wireshark.org/review/35480
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>
2019-12-18 04:31:03 +00:00
Stig Bjørlykke 8afd7a751f funnel: Free callback data
Free one more allocated callback data in TextWindow. This is needed
because text_win_close_cb() is also doing the same as TextWindow__gc().

Bug: 16177
Change-Id: I7c2211e154a6db1dccd22df824e76cce575040c9
Reviewed-on: https://code.wireshark.org/review/34990
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2019-11-05 17:15:42 +00:00
Stig Bjørlykke 499d912f4b funnel: Free callback data
Free allocated callback data in FunnelStringDialog, TextWindow and
registered menu items. Also free strings used in FunnelStringDialog.

Bug: 16177
Change-Id: I9a129b8975a55d1dc89fe851116feebe82763bca
Reviewed-on: https://code.wireshark.org/review/34945
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-11-05 15:21:30 +00:00
Stig Bjørlykke 541afedfbc wslua: Fix memleak of unregistered ProtoExpert
If a ProtoExpert object was created, but not linked to a Proto, then the
object and some fields (abbrev, text) would leak.

This is a follow-up to g79fef2ae.

Change-Id: Ic0b44e8b70895a19d9b52a0e44064a1e76a58fa0
Reviewed-on: https://code.wireshark.org/review/34876
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Roland Knall <rknall@gmail.com>
2019-10-28 16:16:49 +00:00
Stig Bjørlykke 551745998e wslua: Fix memleak of unregistered ProtoField strings
If a ProtoField object was created, but not linked to a Proto, then the
strings field and all elements (depending on type) would leak.

This is a follow-up to g79fef2ae and fixes the real issue in g44870fb1.

Change-Id: I01880a92bb20fae45f68c754b07daeb07630deec
Reviewed-on: https://code.wireshark.org/review/34872
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Vasil Velichkov <vvvelichkov@gmail.com>
Reviewed-by: Roland Knall <rknall@gmail.com>
2019-10-28 15:05:54 +00:00
Stig Bjørlykke 0371994223 wslua: Improve parameter check in ProtoField.new()
Improve paremeter check in ProtoField.new() when using ftypes.CHAR:
- Check valid base types and give an error when not supported instead of
  terminate in a g_error() (base.DEC is not supported).
- Give an error if used with base.UNIT_STRING instead of silently remove
  the flags.
- Support base.RANGE_STRING instead of removing the flag.

Support using base.NONE with a valuestring.
Add ftypes.CHAR to the list of supported types.

Change-Id: I0e3f9698074c807f5da0de23ccd1be7446271135
Reviewed-on: https://code.wireshark.org/review/34783
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-10-16 07:41:11 +00:00
Stig Bjørlykke 3a9933c52f wslua: Add ProtoField.char()
ProtoField.new() already support ftypes.CHAR, so add ProtoField.char()
to complete the support for FT_CHAR in Lua.

Change-Id: I0568f874fd667f834584a07af14bdda9bb03856b
Reviewed-on: https://code.wireshark.org/review/34784
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-10-16 07:40:39 +00:00
Stig Bjørlykke efe1b0b1b2 Lua: Use space for indent
Remove use of TAB.

Change-Id: Ic2a08f6b325e1fc52a5b043aa09e8f98dacd8c5e
Reviewed-on: https://code.wireshark.org/review/34780
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2019-10-15 07:58:27 +00:00
Stig Bjørlykke 8e3ed86de7 Lua: Support FT_CHAR in Field
Add support for fetching FT_CHAR field values.

Bug: 16129
Change-Id: I0e3b0c784277e259fb7cd1725254fc7a723f6d1e
Reviewed-on: https://code.wireshark.org/review/34775
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2019-10-14 17:39:25 +00:00
Guy Harris 22e7952e06 HTTPS In Even More Places, update some links.
Fall back on the Wayback Machine for some links.

Change-Id: I6a44a2caaeb4fa521c2f08196e7c36069e3bb842
Reviewed-on: https://code.wireshark.org/review/34103
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-07-28 04:21:18 +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 Kaiser 429082dd71 wslua: pinfo: make p2p_dir accessible to lua dissectors
Some dissectors populate pinfo->p2p_dir with a packet's direction
(incoming / outgoing). Make this info available to lua dissectors.

Add a simple test for Pinfo's new p2p_dir attribute to the wslua
test suite. It checks that p2p_dir is unknown for dhcp packets.
(The dhcp dissector does not set p2p_dir).

Change-Id: I8cc39a11cff840d10ef7fa94d30cbac8bf9b533f
Reviewed-on: https://code.wireshark.org/review/33935
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Martin Kaiser <wireshark@kaiser.cx>
2019-07-22 15:45:27 +00:00
Peter Wu a80b4fdd40 Lua: remove lua_data_handle
Use call_data_dissector directly for the same effect as lua_data_handle.

Remove the special case where DissectorTable.get_dissector() returns the
data dissector for an unsupported type. The documentation says that nil
is returned if the handle is not found, that seems more appropriate.

Change-Id: I128ef90b79bda925a4329202a0b9956e1cf16200
Reviewed-on: https://code.wireshark.org/review/34032
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Martin Kaiser <wireshark@kaiser.cx>
2019-07-21 17:00:18 +00:00
Martin Kaiser bfad6f03d6 wslua: add a Proto parameter to DissectorTable.new()
Add an optional paramter of type Proto to DissectorTable.new().
If the caller provides a Proto, we can get the protocol id and
use it when we register the dissector table.

Change-Id: I3ab0819c41fa97288ec962d8d495b63d4750ce4b
Reviewed-on: https://code.wireshark.org/review/33608
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-06-16 02:39:18 +00:00
Martin Kaiser 13795914a1 wslua: clean up DissectorTable_new()
Reorder the code to have a single return statement at the end.
Take advantage of the fact that WSLUA_OPTARG_ERROR terminates
the C function that called it.

Do only the parameter checks in the switch-case statement.

Get rid of the intermediate steps when we copy name and ui_name.

Change-Id: Ie8917d19589a6ee16a4a5d14f2c1711d35cc8114
Reviewed-on: https://code.wireshark.org/review/33607
Reviewed-by: Martin Kaiser <wireshark@kaiser.cx>
Petri-Dish: Martin Kaiser <wireshark@kaiser.cx>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-06-16 02:15:05 +00:00
Martin Kaiser bf8bc8e007 wslua: add support for ft_none dissector tables
The C code introduced ft_none dissector tables some time ago. They have
no indicator to select the next protocol, only Decode As is supported
for them.

Allow lua code to create ft_none dissector tables as well. The patch
is trying to make as few changes as possible to DissectorTable_new().

Change-Id: Ie3ff58f092e6922ab7878d202c7484a64b2430a3
Reviewed-on: https://code.wireshark.org/review/33588
Reviewed-by: Martin Kaiser <wireshark@kaiser.cx>
Petri-Dish: Martin Kaiser <wireshark@kaiser.cx>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-06-14 13:39:27 +00:00
Martin Kaiser a3481933f9 wslua: fix error handling for invalid dissector table
Calling DissectorTables's try method for a dissector table of an unknown
type crashes Wireshark.

local dt = DissectorTable.get("iso14443.subdissector")
dt:try(0, tvbuf, pinfo, tree)

causes a segmentation fault

Thread 1 "wireshark" received signal SIGSEGV, Segmentation fault.
except_pop () at /media/sf_wireshark.git/epan/except.c:264
264       set_top(top->except_down);
(gdb) print top
$1 = (struct except_stacknode *) 0x2
(gdb) bt
    at /media/sf_wireshark.git/epan/packet.c:590

My gut feeling (I haven't verified this) is that we should not call luaL_error()
inside a TRY-CATCH block. DissectorTable_try does this when the type of the
dissector table is not supported.

Fall back to the data dissector in this case and bring up an expert info
instead of aborting the dissection completely.

Change-Id: I9a49f738a99b2618014f41050d8c0bf6bfbb4138
Reviewed-on: https://code.wireshark.org/review/33357
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-05-26 13:08:38 +00:00
Martin Kaiser 0ab91dd96a wslua: print the correct type for FT_NONE dissector tables
We added FT_NONE dissector tables a while ago. These tables can only be
used for Decode As. Support such dissector tables in lua's print() function.

print(DissectorTable.get("iso14443.subdissector"))

will now print

DissectorTable iso14443.subdissector only for Decode As:

Change-Id: I9f5a2f6d6b1edb2a53ca1d2c0ae158c16fddf05f
Reviewed-on: https://code.wireshark.org/review/33356
Reviewed-by: Martin Kaiser <wireshark@kaiser.cx>
Petri-Dish: Martin Kaiser <wireshark@kaiser.cx>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-05-26 06:32:58 +00:00
Alexis La Goutte 92dede59a5 wslua(pinfo): fix typo
Change-Id: Ifc808baf3ea495f632be00bcfb122b78d80a7854
Reviewed-on: https://code.wireshark.org/review/33267
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-05-20 07:37:56 +00:00
Peter Wu 0215d34be7 Lua: define table.unpack for Lua 5.1 for compatibility
Lua 5.2 moves unpack to table.unpack, be sure to define this for Lua 5.1
or LuaJIT. This fixes an error with https://github.com/Lekensteyn/kdnet
when using LuaJIT.

Change-Id: Ib9e4591d9edb1cb3b0c1e86172331055f9f457d9
Ping-Bug: 15745
Reviewed-on: https://code.wireshark.org/review/33046
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-05-17 10:19:32 +00:00
Guy Harris 8a5b26efb1 Have wtap_read() fill in a wtap_rec and Buffer.
That makes it - and the routines that implement it - work more like the
seek-read routine.

Change-Id: I0cace2d0e4c9ebfc21ac98fd1af1ec70f60a240d
Reviewed-on: https://code.wireshark.org/review/32727
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-04-05 02:49:43 +00:00
Gerald Combs 8d3ac3af86 epan: Convert our PROTO_ITEM_ macros to inline functions.
Convert our various PROTO_ITEM_ macros to inline functions and document
them.

Change-Id: I070b15d4f70d2189217a177ee8ba2740be36327c
Reviewed-on: https://code.wireshark.org/review/32706
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-04-04 04:03:38 +00:00
Martin Kaiser 6e1d30ce87 wslua: simplify __WSLUA_REGISTER_META and _CLASS
Get rid of ATTRS_BLOCK, which is either empty or sets a value for attr.
We can initialize attr in any case, either to NULL or to the attributes
provided by the caller. This makes the code a bit easier to read (at
least for me).

Change-Id: Ib26ea5ec099b365303de5aaf407470ad48b126f9
Reviewed-on: https://code.wireshark.org/review/32186
Reviewed-by: Martin Kaiser <wireshark@kaiser.cx>
Petri-Dish: Martin Kaiser <wireshark@kaiser.cx>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-02-26 05:32:42 +00:00
Peter Wu 8d7876bace wslua: do not partially disable the Lua API when run as root
Users should not be starting Wireshark as root user (sudo or root
login). If they do, then they can already execute arbitrary code via C
plugins, or read and write arbitrary files. Limiting the Lua API will
not really help these users to prevent breaking their system further.

Therefore remove all artificial restrictions and allow users to run
user-supplied scripts by default. If for whatever policy reason this
flag is set to false, then only Lua dissectors from the global system
directory are executed. It is their responsibility not to provide a free
root shell to the user.

Note that "running_superuser" will also be true if setuid root while the
effective and real user is no longer root. This happens due to
relinquish_special_privs_perm(). In this case, disabling the Lua API is
just annoying with no benefits.

Change-Id: Ie8a38e6160d861f02cbb70dcd1d90462153f4665
Link: https://www.wireshark.org/lists/wireshark-dev/201902/msg00004.html
Reviewed-on: https://code.wireshark.org/review/31913
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Dario Lombardo <lomato@gmail.com>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-02-07 10:30:06 +00:00
Peter Wu 10ef8b717c wslua: do not load console.lua when run as root
dofile is currently disabled whenever Wireshark or tshark was started as
root, calling it will result in Lua errors on startup.

Even if dofile were not disabled, the Lua Evaluate menu option enables
arbitrary Lua code execution. The other options (Console, help links)
are not that important either, so just disable it when run as root.

Change-Id: I0785fe9b3d4678d71ae1e0178811dada471c3525
Link: https://www.wireshark.org/lists/wireshark-dev/201902/msg00004.html
Reviewed-on: https://code.wireshark.org/review/31912
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Dario Lombardo <lomato@gmail.com>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-02-07 10:29:01 +00:00
Stig Bjørlykke 8b75b52254 wslua: Don't defer deletion of subtree indexes
The subtree indexes are only used in the dissector so it's not
needed to defer the deletion.

Change-Id: I33600897a186c078cc1021cde5a1d90054d475c8
Reviewed-on: https://code.wireshark.org/review/31800
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-01-29 14:30:37 +00:00
Stig Bjørlykke 2b7875b905 wslua: Update wslua_register_menu() documentation
Add missing group values. Update regex to match TELEPHONY_MTP3.

Change-Id: I709a416e30d79c2de69887548015a3c1ecfe5bab
Reviewed-on: https://code.wireshark.org/review/31779
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-01-29 05:47:05 +00:00
Stig Bjørlykke 8b684769a8 wslua: Improve syntax error message
The filename is included in the error message from Lua so we don't
need to display this twice.

Change-Id: I00aa7255ff24b07b9f45a8e814a97b61c35936e1
Reviewed-on: https://code.wireshark.org/review/31768
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2019-01-28 13:22:22 +00:00
Peter Wu 8003c0dd75 lua: fix build with Lua 5.1 due to missing LUA_OK macro
Change-Id: If367f79172c8222c65fd9d95a050e75194df852d
Fixes: v2.9.1rc0-556-g6a49c72974 ("wslua: include Lua stack trace in startup error messages")
Reviewed-on: https://code.wireshark.org/review/31771
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-01-28 11:54:08 +00:00
Peter Wu 6a49c72974 wslua: include Lua stack trace in startup error messages
Error messages without a stack trace are rather hard to debug for more
complex Lua dissectors. Be sure to append one, it will look like this:

    tshark: Lua: Error during loading:
     /tmp/kdnet/kdnet.lua:13: bad argument #3 to 'proto_field_constructor' (Display must be either base.NONE, base.DOT, base.DASH, base.COLON or base.SPACE)
    stack traceback:
            [C]: in function 'proto_field_constructor'
            /tmp/kdnet/kdnet.lua:13: in function 'add_field'
            /tmp/kdnet/kdnet.lua:35: in function 'add_fields'
            /tmp/kdnet/kdnet.lua:242: in main chunk

It would be nice to reuse the error handler for dissector calls as well,
but I am not sure whether this works with absolute indices which are
used almost everywhere in wslua.

Change-Id: I89b2dcd360fce3865e1bf052b9fe03e888aae167
Reviewed-on: https://code.wireshark.org/review/31763
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-01-28 11:04:23 +00:00
Peter Wu e3a9cc6761 wslua_pinfo: fix memleaks on setting addresses in Pinfo
Fixes memory leaks reported by ASAN for the test_wslua_pinfo test.

Change-Id: Id7e79e63559db1e7f8b27d566048eab9268d9237
Reviewed-on: https://code.wireshark.org/review/31754
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-01-27 09:43:44 +00:00
Peter Wu 79fef2ae50 wslua: fix memleak of unregistered ProtoField field
If a ProtoField object was created, but not linked to a Proto, then some
fields (name, abbrev, blob) could leak. Fixes ASAN test failures for
four wslua tests.

Change-Id: I570ea154153b505ba81edb2bbf538e6dc1438728
Reviewed-on: https://code.wireshark.org/review/31750
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-01-27 09:43:26 +00:00
Peter Wu 03e13a6a9f wslua: fix memleaks related to Proto and Pref
Proto objects were only freed while reloading Lua plugins, be sure to
release these on program exit too. Fix missing deallocation of heur_list
(matches per-protocol cleanup in proto_cleanup_base).

Be sure to keep a reference to the "Pref" object after registering it to
a Proto, otherwise it could be garbage-collected early, resulting in
memleaks (because the preference was still in use).

Fixes a lot of memory leaks reported by ASAN for tests, ten tests were
affected by Proto_new leaks, four were affected by the new_pref leaks.

Change-Id: Ica52718849a33eda614775f533dc0fcefec9cc74
Reviewed-on: https://code.wireshark.org/review/31746
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-01-27 09:43:05 +00:00
Peter Wu 311d087bbd wslua_listener: fix memleak in tap packet callback
Addresses memleaks reported by ASAN for:

    test_wslua_listener
    test_wslua_nstime
    test_wslua_pinfo
    test_wslua_field

Change-Id: I221382844ee0bfd7ffc274bbb27eded0e221f9cf
Reviewed-on: https://code.wireshark.org/review/31742
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-01-27 09:40:56 +00:00
Peter Wu 141f6d8df9 wslua_field: fix memory leaks in Field_new
Change the "Field" type to actually point to a structure. Do not cheat
and overload the pointer to mean "char*" in one context, and
"header_field_info*" in another. It was very confusing.

Implement Field__gc to free the Field structure that was allocated in
Field_new. This fixes the memory leak in Field_new.

Now the test_wslua_field test passes when executed with ASAN and a bunch
of other wslua tests also improve.

Change-Id: Ibc4318b76bb893151fd40c3fbc595402fba7a60a
Reviewed-on: https://code.wireshark.org/review/31743
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2019-01-26 19:43:05 +00:00
Peter Wu 6fbf28f3b8 wslua_nstime: fix memleak for bad arguments to NSTime
luaL_optinteger will raise an error when the argument is an invalid
number. Delay the allocation to avoid a leak. Fixes the
test_wslua_nstime test under ASAN.

Change-Id: I6856fd218897565a60786d820f43192b41d489f2
Reviewed-on: https://code.wireshark.org/review/31744
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-01-26 09:07:32 +00:00
Peter Wu 728183c27e wslua_file_handler: fix leak of opt_comment
Since v2.9.1rc0-528-g31aba351e2, it is clear that wtap file formats
should free earlier comments before writing a new one. Do so.
Fixes leaks reported by ASAN for test_wslua_file_acme_reader.

Change-Id: Iafb643f01f5973f2d3b88f244ee70e8c0c451080
Reviewed-on: https://code.wireshark.org/review/31738
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-01-26 07:42:00 +00:00
Peter Wu 31aba351e2 wiretap: fix memleaks with wtap_rec::opt_comment
The memory ownership of wtap_rec::opt_comment was not clear. Users of
wtap were leaking memory (editcap.c). wtap readers were not sure about
freeing old comments (erf) or simply ignored memleaks (pcapng).

To fix this, ensure opt_comment is owned by wtap_rec and free it with
wtap_rec_cleanup. The erf issue was already addressed since
cf_get_packet_comment properly duplicates wth.opt_comment memory.

- wtap file formats (readers):
  - Should allocate memory for new comments.
  - Should free a comment from an earlier read before writing a new one.
- Users of wth:
  - Can only assume that opt_comment remains valid until the next read.
  - Can assume that wtap_dump does not modify the comment.
  - For random access (wtap_seek_read): should call wtap_rec_cleanup
    to free the comment.

The test_tshark_z_expert_comment and test_text2pcap_sip_pcapng tests now
pass when built with ASAN.

This change was created by carefully looking at all users opt
"opt_comment" and cf_get_packet_comment. Thanks to Vasil Velichkov for
an initial patch which helped validating this version.

Bug: 7515
Change-Id: If3152d1391e7e0d9860f04f3bc2ec41a1f6cc54b
Reviewed-on: https://code.wireshark.org/review/31713
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Vasil Velichkov <vvvelichkov@gmail.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-01-25 04:53:10 +00:00
Martin Kaiser 965248dcfb wslua: register attributes along with their class
At the moment, wslua first registers a class and then adds its
attributes in a second step. This registration creates empty __getters
and __setters tables which are later populated with the getter and
setter methods of the attributes.

Looking at the code and the comments, it seems that this was meant to be
a temporary solution. Eventually, attributes should be stored in
wslua_class' attrs field. The code to read and write attributes was
already updated to handle this.

Add new macros WSLUA_REGISTER_CLASS/_META_WITH_ATTRS that store the
attributes in wslua_class. Defining new macros is simpler than modifying
WSLUA_REGISTER_CLASS/_META to register attributes. If we did the latter,
we'd have to add an empty attribute list for all classes without
attributes.

We can now drop the WSLUA_REGISTER_ATTRIBUTES macro and the
wslua_reg_attributes function.

Using this new way of registering attributes, the __getters and
__setters tables are still available. The tests is the test suite that
rely on those tables still pass.

Change-Id: I526b9116435645c9c54ab69a05c3c7f3d459ec33
Reviewed-on: https://code.wireshark.org/review/31417
Reviewed-by: Martin Kaiser <wireshark@kaiser.cx>
Petri-Dish: Martin Kaiser <wireshark@kaiser.cx>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-01-21 11:51:01 +00:00
Guy Harris fd93f5490c Clarify the name and description for a link-layer encapsulation type.
What we were calling the "name" is actually a description to show to
users; what were calling the "short name" is just the name to use on the
command line.

Rename some routines and structure members, and put the name first and
description second in the table.

Expand some descriptions to give more details (e.g., to be more than
just a capitalized version of the name).

Fix the CamelCase capitalization of InfiniBand.

Change-Id: I060b8bd86573880efd0fab044401b449469563eb
Reviewed-on: https://code.wireshark.org/review/31472
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-01-09 21:21:56 +00:00
Guy Harris 2d41b15495 Add a "failed" return for tap packet routines.
This allows taps that can fail to report an error and fail; a failed
tap's packet routine won't be called again, so they don't have to keep
track of whether they've failed themselves.

We make the return value from the packet routine an enum.

Don't have a separate type for the per-packet routine for "follow" taps;
they're expected to act like tap packet routines, so just use the type
for tap packet routines.

One tap packet routine returned -1; that's not a valid return value, and
wasn't one before this change (the return value was a boolean), so
presume the intent was "don't redraw".

Another tap routine's early return, without doing any work, returned
TRUE; this is presumably an error (no work done, no need to redraw), so
presumably it should be "don't redraw".

Clean up some white space while we're at it.

Change-Id: Ia7d2b717b2cace4b13c2b886e699aa4d79cc82c8
Reviewed-on: https://code.wireshark.org/review/31283
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-01-01 05:03:42 +00:00
Peter Wu 07cfef9e5a Revert "Add routines to load Lua programs that assume the path is UTF-8 on Windows."
This reverts commit 5953756305.

The public API should not be polluted with Windows-specific hacks. As we
already override dofile/loadfile, those should be fixed instead.

Ping-Bug: 15118
Change-Id: Ia9d5e64e8ef14032f982f695ffd4cac59067bb17
Reviewed-on: https://code.wireshark.org/review/31134
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-12-30 07:49:22 +00:00
Peter Wu 53d8e6dcf8 Lua: fix crash in reloading Lua plugins that use FileHandler
Reloading Lua plugins did not actually remove registered FileHandler
instances which resulted in a use-after-free of lua_State. Fix this by
tracking instances and release them in wslua_deregister_filehandlers.

Other required fixes to allow reregistration after reloading:
- Fix END_FILEHANDLER_ROUTINE not to block all new registrations.
- wtap file subtypes are apparently persistent, even after
  "unregistering". Fix this by looking up the previous subtype that
  matches the FileHandler short name. Add a small sanity check to
  wtap_register_file_type_subtypes to prevent internal handlers from
  being overwritten.

This patch creates a potential memleak of registered_file_handlers as
wslua_deregister_filehandlers is not called on program exit (yet?).

Bug: 13264
Change-Id: I4f5935cde6ff8dc4de333359bad3efca96d4fb9b
Reviewed-on: https://code.wireshark.org/review/31068
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2018-12-29 10:38:13 +00:00
Guy Harris 7eb3e47fa4 Try to squeeze some bytes out of the frame_data structure.
Make the time stamp precision a 4-bit bitfield, so, when combined with
the other bitfields, we have 32 bits.  That means we put the flags at
the same structure level as the time stamp precision, so they can be
combined; that gets rid of an extra "flags." for references to the flags.

Put the two pointers next to each other, and after a multiple of 8 bytes
worth of other fields, so that there's no padding before or between them.

It's still not down to 64 bytes, which is the next lower power of 2, so
there's more work to do.

Change-Id: I6f3e9d9f6f48137bbee8f100c152d2c42adb8fbe
Reviewed-on: https://code.wireshark.org/review/31213
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-12-27 04:34:29 +00:00
Gerald Combs 060811713f Lua: Fix compilation with Lua 5.1.
Change-Id: Idd4aa36ee95e985560867094d423128e51aacfb1
Reviewed-on: https://code.wireshark.org/review/31095
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2018-12-18 17:43:17 +00:00
Guy Harris 5953756305 Add routines to load Lua programs that assume the path is UTF-8 on Windows.
Add ws_dofile() and ws_loadfile(), which are like the substitute
dofile() and loadfile() we provide, but that, on Windows, take a UTF-8
path rather than a path in the local code page.

Use that to load console.lua.

This means we can load console.lua on Windows even if the full path to
it includes non-ASCII characters.

Bug: 15118
Change-Id: Iaa00639563fe53a34e1e24e42022f3886a38e7c5
Reviewed-on: https://code.wireshark.org/review/31075
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-12-17 21:55:23 +00:00
João Valverde c3741a653b CMake: Simplify CMAKE_INSTALL_DATADIR usage
Change-Id: I414aa551b8e9315a654f4da62b882e787d4f6d53
Reviewed-on: https://code.wireshark.org/review/30904
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot
Reviewed-by: João Valverde <j@v6e.pt>
2018-12-03 22:35:37 +00:00
João Valverde f4194b128f CMake: Change some install() paths to match NSIS package
Currently our Windows code looks for data files in the same
folder as the binary executable (presumably to make the
application relocatable, although it should be possible
to improve this with relative paths?).

Ping-Bug: 15301
Change-Id: I0fef4e87dc9d1d8edef81dd11755761fddd0fd12
Reviewed-on: https://code.wireshark.org/review/30819
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot
Reviewed-by: João Valverde <j@v6e.pt>
2018-11-29 03:19:53 +00:00
Guy Harris a1372f6d01 Use an enum for compression types in various interfaces.
This:

1) means that we don't have to flag the compression argument with a
comment to indicate what it means (FALSE doesn't obviously say "not
compressed", WTAP_UNCOMPRESSED does);

2) leaves space in the interfaces in question for additional compression
types.

(No, this is not part 1 of an implementation of additional compression
types, it's just an API cleanup.  Implementing additional compression
types involves significant work in libwiretap, as well as UI changes to
replace "compress the file" checkboxes with something to indicate *how*
to compress the file, or to always use some other form of compression).

Change-Id: I1d23dc720be10158e6b34f97baa247ba8a537abf
Reviewed-on: https://code.wireshark.org/review/30660
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-11-16 09:20:36 +00:00
Guy Harris 4e17bd6229 Use the dump parameters structure for non-pcapng-specific stuff.
Use it for all the per-file information, including the per-file
link-layer type and the per-file snapshot length.

Change-Id: Id75687c7faa6418a2bfcf7f8198206a9f95db629
Reviewed-on: https://code.wireshark.org/review/30616
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2018-11-16 02:18:26 +00:00
Guy Harris 3faa45d4ec Don't have _ng versions of the dumper open routines.
Have the routines always take a parameters pointer; pass either null or
a pointer to an initialized-to-nothing structure in cases where we were
calling the non-_ng versions.

Change-Id: I23b779d87f3fbd29306ebe1df568852be113d3b2
Reviewed-on: https://code.wireshark.org/review/30590
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-11-13 03:37:29 +00:00
Martin Kaiser 178001e74d lua: add support for ethernet addresses to the Address class
The code for the Address class already contains commented-out code for a
number of additional address types.

Activate the draft constructor for ethernet addresses and complete it.
Use the newly-added function to parse a string that contains an ethernet
address.

Add a basic test tvb.lua. Read an ethernet address from a tvb and
compare it to a constant Address.ether object.

Change-Id: I9771dd6e7ade4b572a8b864b8986d641b4eba3e5
Reviewed-on: https://code.wireshark.org/review/30163
Reviewed-by: Martin Kaiser <wireshark@kaiser.cx>
Petri-Dish: Martin Kaiser <wireshark@kaiser.cx>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2018-10-18 07:51:36 +00:00
Richard Sharpe 6eba988f7c wslua: Add support for base.RANGE_STRING handling.
A range string is passed as a table of tables, eg:

  range_string = {
     { 0, 24, "Some string for values 0 to 24" },
     { 25, 25, "The string for value 25" },
     { 26, 255, "The string for the remainder" }
  }

Included is a minimal Lua test for range strings and value strings
(which did not have one previously.) It will take more time than I
currently have to figure out how to do a more exhaustive test.

Also fixed some grammar issues in error messages along the way.

Change-Id: Ia9d1efc8adabb6528c4bdcf1624c9ede49e2fdc6
Reviewed-on: https://code.wireshark.org/review/30211
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Richard Sharpe <realrichardsharpe@gmail.com>
2018-10-17 20:08:57 +00:00
Guy Harris e7dec27ea0 Show the *per-file* encapsulation in the __tostring method.
We use the per-file encapsulation everywhere else; use it there as well.

Change-Id: I3e3df234a9f541a9d90e54a3c0f41b5019e00bb3
Reviewed-on: https://code.wireshark.org/review/29940
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-09-30 21:07:28 +00:00
Gerald Combs 50dbe4df7f Rename packet-ssl* to packet-tls*
Rename packet-ssl{,-utils}.[ch] to packet-tls{,-utils}.[ch].

Change-Id: I4732162ec131ddf0734b3dd191ccc9e48a76ce06
Reviewed-on: https://code.wireshark.org/review/29659
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-09-25 13:24:17 +00:00
Peter Wu 71c7798f8a epan: fix various misannotations of VALS/RVALS/VALS64/TFS
No functional change, just using the correct macro for value_strings.
Other fixes: Taking the address of the first element of an array gives
the same address as the array itself. An array of a structure with a
single element is the same as the single element itself (packet-sprt.c).

Change-Id: I08bc9de49fbd1659a6700ace863e5f05144c7b3e
Reviewed-on: https://code.wireshark.org/review/29752
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
2018-09-20 05:06:07 +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
Guy Harris e31ca2e278 Revert "Some older compilers don't allow diagnostic pragmas inside a function."
This reverts commit f94cfa0cdc.

Reason for revert: we don't use those diagnostic pragmas with those
older compilers.

Change-Id: I5154527dcc3813fb893c382059cb33538f2d29f7
Reviewed-on: https://code.wireshark.org/review/29639
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-09-12 16:29:30 +00:00
Guy Harris f94cfa0cdc Some older compilers don't allow diagnostic pragmas inside a function.
Change-Id: I7ed32cfdd1c7a308acf5ef2cca9fde28dda5563e
Reviewed-on: https://code.wireshark.org/review/29600
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-09-11 10:43:36 +00:00
Peter Wu 6fa2ad4922 Lua: remove various logging functions (debug, warn, etc.)
The "debug" logging function overwrites the "debug" package which breaks
luacov: https://github.com/keplerproject/luacov/issues/55

Change-Id: I9b6025c060733198bfff8ea959444c09d6e08709
Reviewed-on: https://code.wireshark.org/review/29449
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-09-07 04:02:45 +00:00
Peter Wu 46e71f9a7c wslua: fix source argument in debug info for luacov
The source argument should start with a '@', otherwise it is treated as
actual source code instead of a filename. This is needed for luacov. See
https://www.lua.org/manual/5.2/manual.html#lua_Debug
https://github.com/keplerproject/luacov/issues/55

Change-Id: I0a3e2da65fb6b4aaabb9173a07fdea18a788f3e3
Reviewed-on: https://code.wireshark.org/review/29447
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-09-07 04:02:25 +00:00
Stig Bjørlykke 0b80a42187 epan: Guard g_base64_decode_inplace() against zero length string
The g_base64_decode_inplace() does not handle zero length string
so add a guard for this before calling.

Bug: 15113
Change-Id: I89fa17dd62af238f4282835c317e5c8be6e0c8a1
Reviewed-on: https://code.wireshark.org/review/29428
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2018-09-05 17:19:42 +00:00
Stig Bjørlykke 65b342f749 epan: Use g_base64_decode_inplace()
Replace ws_base64_decode_inplace() with g_base64_decode_inplace()
or g_base64_decode(), which was introduced in glib 2.12.

The only observed difference is a need for zero-terminate the buffer
after decoding.

Change-Id: Ia102d0d8e9bec575ffeddf448191a3f6de9fb1ed
Reviewed-on: https://code.wireshark.org/review/29382
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-09-03 04:05:13 +00:00
João Valverde 8eddb1650d epan: Remove unnecessary all protocols registration callback
We are exporting a registration function from libwireshark just
to have it passed back as a callback. Seems unnecessary.

Change-Id: I7621005c9be11691d319102326824c5e3520a6f3
Reviewed-on: https://code.wireshark.org/review/29328
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot
Reviewed-by: João Valverde <j@v6e.pt>
2018-08-29 23:22:44 +00:00
Guy Harris 9b731e2b32 Add a tap "finish" callback, called when a listener is removed.
Change-Id: Ic6c23dbd39d1adf8f730f1c866e409f731947475
Reviewed-on: https://code.wireshark.org/review/28786
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-07-21 00:51:13 +00:00
Gerald Combs 61dd06ed9f Lua: Switch from disable_lua to enable_lua.
Deprecate "disable_lua" in favor of "enable_lua". Configuration options
typically use "true" or a similar value to enable features. Using
"disable_lua = false" to enable Lua seems odd.

Change-Id: I224acad0559d409ea0a28b5555d1eb898564328c
Reviewed-on: https://code.wireshark.org/review/28773
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-07-20 06:42:38 +00:00
Peter Wu a1e5a15780 wslua: fix NSTime:__tostring for negative values
"nstime_t{A, B}" is defined as "A + B * 10^9" rather than an integer
part A and fractional part B.

Bug: 14720
Change-Id: I5321db7d5ecea8f976291d2a22667b02162194e2
Reviewed-on: https://code.wireshark.org/review/27775
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-05-25 12:50:18 +00:00
Peter Wu 10306f9a32 Free g_array_free-related memory leaks
g_array_free(a, FALSE) returns "a->data". Callers that do not handle
this will leak memory. Convert other users to use the return value
instead of direct access to "a->data".

Change-Id: I0a29864e8106c0bf09e9573ef29e4474179c4171
Reviewed-on: https://code.wireshark.org/review/27438
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2018-05-14 13:44:23 +00:00
Peter Wu bb81e1807b Free g_ptr_array_free-related memory leaks
g_ptr_array_free(a, FALSE) returns "a->pdata". Callers that do not
handle this will leak memory (e.g. "tshark -G plugins"). Convert other
users to use the return value instead of direct access to "a->pdata".

Change-Id: I29835477d587f5f54bf0d94cdae9f375e3da3ce3
Reviewed-on: https://code.wireshark.org/review/27437
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2018-05-14 13:42:10 +00:00
Peter Wu a729c0f173 wslua: fix memleak in Dir.remove_all on error path
While at it, use g_build_filename. Found by Clang Static Analyzer.

Change-Id: I5c50f50abb8c16a553586c548ccd1ae6c3cdd8c1
Reviewed-on: https://code.wireshark.org/review/27439
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-05-10 06:16:19 +00:00
Guy Harris 8db1616ec3 Get rid of more autotoolsisms.
Change-Id: I124732adf3c3da511c206932544b4d533404cfc5
Reviewed-on: https://code.wireshark.org/review/27332
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-05-04 19:14:34 +00:00
João Valverde 9988267d1b Lua: Remove autotools specific code for build path
Change-Id: I541bd728c159e95c2d5daa8ce0bfea3961ff1db9
Reviewed-on: https://code.wireshark.org/review/27203
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: João Valverde <j@v6e.pt>
2018-04-30 11:15:10 +00:00
Peter Wu b9f915eeef Lua: ensure that DATA_DIR and USER_DIR have trailing slashes
These directories have had trailing slashes for years and users seem to
rely on it, so restore this assumption for backwards compatibility. The
underlying API function (Dir.persconffile_path()) is not changed because
trailing slashes were not documented for that function.

For consistency, ensure that all Lua Dir functions return paths without
trailing slashes.

Bug: 14619
Change-Id: Ia299864999578884b1ad1cd48f1bd883bce6879d
Fixes: v2.5.0rc0-579-gfb052a637f ("Use g_build_filename() instead, fix indentation")
Reviewed-on: https://code.wireshark.org/review/27166
Reviewed-by: João Valverde <j@v6e.pt>
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2018-04-30 10:33:46 +00:00
Dario Lombardo 4a156da068 Remove autotools build system.
It has been replaced by cmake.

Change-Id: I83a5eddb8645dbbf6bca9f026066d2e995d8e87a
Reviewed-on: https://code.wireshark.org/review/26969
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-04-18 03:46:17 +00:00
Guy Harris c7970d9356 Add, and use, "fetch signed value" for lengths < 40 bits.
Add 8-bit, 16-bit, 24-bit, and 32-bit "fetch signed value" routines, and
use them rather than casting the result of the 8/16/24/32-bit "fetch
unsigned value" routines to a signed type (which, BTW, isn't sufficient
for 24-bit values, so this appears to fix a bug
in epan/dissectors/packet-zbee-zcl.c).

Use numbers rather than sizeof()s in various tvb_get_ routines.

Change-Id: I0e48a57fac9f70fe42de815c3fa915f1592548bd
Reviewed-on: https://code.wireshark.org/review/26844
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-04-10 14:55:45 +00:00
Peter Wu 4847076c7f wslua: Fix logging
Always display Lua messages (to match tshark), do not send them to
qDebug as they will not be visible with the default log options.

Change-Id: I660a3877355891d45881b26735596ea6dc8a8b29
Fixes: v2.5.0rc0-2037-gc9b6887d84 ("wslua: Fix logger after g6a5e90f2")
Reviewed-on: https://code.wireshark.org/review/26599
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-03-24 07:17:03 +00:00
Peter Wu dc2f4bdf26 wslua: use Filehandler.extensions for controlling output files
Allow FileHandlers to specify the extension that is used for saved
files. Implementation note: previously "fh->extensions" was unused;
memory is not freed anywhere because registered file handlers can
currently not be destroyed.

Bug: 14386
Change-Id: I65509c10a678fc6af0cf6a4c5c8aed56e79ea34a
Reviewed-on: https://code.wireshark.org/review/26399
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2018-03-15 20:04:20 +00:00
Dario Lombardo e7ab7a907c spdx: more licenses converted.
Change-Id: I8f6693108c43959e54911d35b4fbf730c59add60
Reviewed-on: https://code.wireshark.org/review/26361
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-03-09 04:50:23 +00:00
Guy Harris 695fbb9be0 Squelch some casting-away-constness warnings.
In true_false_string_from_table(), keep the pointers to the "true" and
"false" strings in local non-const pointer variables, so we can free
them without a complaint.

Only when we're finished, and have valid "true" and "false" strings, do
we allocate the true_false_string structure and fill it in with those
pointers.

Change-Id: I6eb3ee46bdc47bf42d6e913c72884f0eac22997e
Reviewed-on: https://code.wireshark.org/review/26353
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-03-08 04:10:04 +00:00
Dario Lombardo fe71e26af2 spdx: more licenses converted.
Change-Id: I3861061ec261e63b23621799e020e811ed78a343
Reviewed-on: https://code.wireshark.org/review/26333
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-03-07 15:56:44 +00:00
Dario Lombardo 8a5385b9c9 More licenses converted to SPDX.
Change-Id: Id4f987dcdacf06622d70263f4659a4400e30dc39
Reviewed-on: https://code.wireshark.org/review/26332
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-03-07 13:35:49 +00:00
Gerald Combs 5a674d05c9 wslua: Convert more comment markup to Asciidoctor.
Convert links, source code blocks, and admonitions.

Change-Id: I50c8daa19a115c23f7501b91dbfd904779a609c9
Reviewed-on: https://code.wireshark.org/review/25720
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
2018-02-11 17:12:52 +00:00
Dario Lombardo 5a94c7d14e epan: more SPDX convertions.
Change-Id: I3c9ba4542c50321ce60cba68696d99575a735392
Reviewed-on: https://code.wireshark.org/review/25708
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-02-09 14:41:31 +00:00
Dario Lombardo ff6e2fbb1b wslua: use SPDX identifiers.
Change-Id: I80d9d4e3ffc25eebf09e6ef693c378b77554e1b8
Reviewed-on: https://code.wireshark.org/review/25693
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-02-09 12:31:21 +00:00
Guy Harris 1f5f63f8ef Generalize wtap_pkthdr into a structure for packet and non-packet records.
Separate the stuff that any record could have from the stuff that only
particular record types have; put the latter into a union, and put all
that into a wtap_rec structure.

Add some record-type checks as necessary.

Change-Id: Id6b3486858f826fce4b096c59231f463e44bfaa2
Reviewed-on: https://code.wireshark.org/review/25696
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-02-09 00:29:51 +00:00
Dario Lombardo 8cd389e161 replace SPDX identifier GPL-2.0+ with GPL-2.0-or-later.
The first is deprecated, as per https://spdx.org/licenses/.

Change-Id: I8e21e1d32d09b8b94b93a2dc9fbdde5ffeba6bed
Reviewed-on: https://code.wireshark.org/review/25661
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-02-08 14:57:36 +00:00
Guy Harris cb1a6528f9 Get rid of the pkt_encap field in struct packet_info.
pinfo->pkt_encap is jsut a copy of pinfo->phdr->pkt_encap; no need for
the copy.

Expand a comment while we're at it.

Change-Id: I5fcfe694ecba42507f1d629d01440da0a0989501
Reviewed-on: https://code.wireshark.org/review/25643
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-02-06 20:35:47 +00:00
Guy Harris ebb471f211 Clean up addition of FT_IPv{4,6} fields.
The data for an address is *not* guaranteed to be aligned on any
particular boundary, so, for IPv4 addresses, don't assume it's aligned
on a 32-bit boundary - copy it with memcpy() and use the result of the
copy.

For IPv6 addresses, cast the data pointer to a pointer to a *const*
ws_in6_addr, so we don't throw away constness.

Change-Id: I0e00263f594d7778c3bd9b98e4336cb201c1f3d5
Reviewed-on: https://code.wireshark.org/review/25580
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-02-03 21:16:08 +00:00
Gerald Combs f5a8711ef1 Qt: About dialog updates.
Open lua scripts when double-clicked. Behavior depends on your system
configuration. Add tooltips accordingly.

Let Qt wrap the "Wireshark" tab information.

Set column widths by eyeballing their contents.

Elide the Folders and Plugins strings in the middle.

Fixup placeholder text capitalization.

Draw links using the palette link color.

Change-Id: Ic141eae05541480ec1e254c55fd81728d04713d9
Reviewed-on: https://code.wireshark.org/review/25510
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-01-31 04:55:37 +00:00
Jakub Zawadzki d672ee9372 wslua: fix nstime memory leak after passing unknown encoding to TvbRange_nstime()
Move checking of encoding before allocating nstime.
Found by clang.

Change-Id: I3c1de5fae6fcf52393cc38302359f21f17808087
Reviewed-on: https://code.wireshark.org/review/25442
Petri-Dish: Jakub Zawadzki <darkjames-ws@darkjames.pl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-01-24 08:34:32 +00:00
Martin Mathieson 137ab7d568 potential buffer underflow in File_read_line function in epan/wslua/wslua_file.c
Putting up for review, though I am not completely convinced that
file_gets() can return an empty line.

Bug: 14295
Change-Id: If36761ea511b66c01a9f167809a218a7eadbfcc5
Reviewed-on: https://code.wireshark.org/review/24997
Petri-Dish: Martin Mathieson <martin.r.mathieson@googlemail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2017-12-26 20:21:04 +00:00
Stig Bjørlykke c9b6887d84 wslua: Fix logger after g6a5e90f2
The Qt log output changes in g6a5e90f2 changed the Qt message handler
to use g_log.  Lua logging already used g_log.  The Qt variant of
funnel logger, which is used by Lua as g_log backend, is currently
using qDebug and this gives recursive calls to g_log and thus an assert.

Rewrite the lua logging to not use g_log.

Change-Id: Icf4f0022a11cb32d2b4f413f76d946f2506e283d
Reviewed-on: https://code.wireshark.org/review/24888
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2017-12-19 12:18:20 +00:00
Stig Bjørlykke 3d086e638d wslua: Fix crash in Dir.open()
Do not give an uninitialised error pointer to g_dir_open(), this
will give a crash if g_dir_open() fails.

Remove wslua_dir.dummy because it is not used by anyone.

Change-Id: I044eee021393f2ea2aa022138bbf6fd099eb0908
Reviewed-on: https://code.wireshark.org/review/24840
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-12-16 04:03:41 +00:00
Stig Bjørlykke 28ba566675 wslua: Fix memory leakages
Free some variables in error handling.

Change-Id: I0d0653962b11f760c31872aa7e5b5f1d20c54dcb
Reviewed-on: https://code.wireshark.org/review/24842
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-12-16 03:12:00 +00:00
Stig Bjørlykke 862a0b6472 epan: Make expert info summary text mandatory
This will make the code easier and removes the use of a generic
"Expert Info" as name.

Change-Id: I57ad2adb851726106ddc5009f3c6ca61721f647a
Reviewed-on: https://code.wireshark.org/review/24792
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2017-12-14 06:06:47 +00:00
Stig Bjørlykke f945b85391 epan: Use expert info summary text as field name
Change the expert info registry to use summary text as field name instead
of blurb to show the correct column header tooltip in custom columns.

Preserve backward compability by not use empty summary text.

Change-Id: Ibbaf142165be0d9f42d1e2476f39f8d251ea0593
Reviewed-on: https://code.wireshark.org/review/24788
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2017-12-13 10:35:36 +00:00
João Valverde 7540ac6938 Move the protocol registration routines back into libwireshark
Follow-up to b695b3e2f7.

Change-Id: I7e36519f2c3806c1205d05437671325080974257
Reviewed-on: https://code.wireshark.org/review/24524
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot
Reviewed-by: João Valverde <j@v6e.pt>
2017-11-21 20:21:50 +00:00
João Valverde 1097e8020a autotools: Library build products don't need explicit cleaning
Change-Id: I5d68c05f2844d6c9ae486531b189dbf10bc09cff
Reviewed-on: https://code.wireshark.org/review/24484
Reviewed-by: João Valverde <j@v6e.pt>
2017-11-18 22:29:41 +00:00
Michael Mann 800b26edbe Remove circuit API
Replace with conversation API that limits the "endpoint" to a single
uint32 value.

The intention is to eventually have "layered" endpoints, because circuit_id
was used in cases where src/dest port have already been populated (and
are used for layers above).  Those src/dest ports should just be treated
as just another endpoint, but we currently only have support for one.

Change-Id: Ic6aa7ef0241275aa4dfde9459194369b48c72960
Reviewed-on: https://code.wireshark.org/review/24369
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2017-11-13 05:21:36 +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
João Valverde 9764cd0a83 autotools: make maintainer-clean should allow rerunning 'configure'
Change-Id: Iedae94ffefe27b13b1967d69cacb757b5aa4576d
Reviewed-on: https://code.wireshark.org/review/23928
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: João Valverde <j@v6e.pt>
2017-10-15 14:17:20 +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
João Valverde 9bba3866ff CMake: Allow user build flags to override default build flags
Autotools has the very useful feature by design of allowing the user
to override the default build flags (you break it you keep it).

Apparently CMake applies COMPILE_OPTIONS target property after
CMAKE_{C,CXX}_FLAGS so that doesn't work here. Prepend our flags to those
variables instead to make it work then.

Specific target flag overrides can still be added with COMPILER_OPTIONS
(e.g: generated files with -Wno-warning) but this is less effective and
then we're back at the point where this overrides user flags. It's less
of a concern though.

Change-Id: I44761a79be4289238e02d4e781fef0099628817b
Reviewed-on: https://code.wireshark.org/review/23675
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: João Valverde <j@v6e.pt>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2017-10-13 21:32:18 +00:00
João Valverde 6be572006e plugins: Add backward compatibility for personal lua scripts
Relax requirements for upgrades and make running side-by-side installations
more convenient.

Change-Id: I5299eed005a4748c54465dec90f477adb577e056
Reviewed-on: https://code.wireshark.org/review/23619
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: João Valverde <j@v6e.pt>
2017-09-20 17:07:47 +00:00
João Valverde 8db4ddd40c Rename get_plugin_dir() for consistency
WS_DLL_PUBLIC const char *get_plugin_dir(void);
WS_DLL_PUBLIC const char *get_plugins_pers_dir(void);

Opt for the plural form consistently (for public functions at least).

Change-Id: I8a5861ad7f90f9c87168bd3275bd9dbc5c83b749
Reviewed-on: https://code.wireshark.org/review/23608
Petri-Dish: João Valverde <j@v6e.pt>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-09-20 01:00:37 +00:00
Stig Bjørlykke ccc5b44dea wslua: Disable -Wunreachable-code in lua_bitop.c
Some code is unreachable in some configurations.

Change-Id: I23ff9a6032f4f7f6eb8e6607c6473a77a8bb6ac6
Reviewed-on: https://code.wireshark.org/review/23561
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-09-15 20:46:46 +00:00
Stig Bjørlykke e84c2e03e4 wslua: Avoid possible misuse of comma operator warning
Change-Id: I441359741332aa49fb91ded438cf2ec3d70b5e0f
Reviewed-on: https://code.wireshark.org/review/23560
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-09-15 20:21:01 +00:00
João Valverde 69f0cb0cef wsutil: Initialize and store plugin personal dir
Obviate allocation on every call to get_plugins_pers_dir().

Change-Id: I089ae499f93739d490d4552f59b5db5996f7d26f
Reviewed-on: https://code.wireshark.org/review/23495
Petri-Dish: João Valverde <j@v6e.pt>
Reviewed-by: Michael Mann <mmann78@netscape.net>
Reviewed-by: João Valverde <j@v6e.pt>
2017-09-11 16:48:49 +00:00