Commit Graph

45 Commits

Author SHA1 Message Date
Gerald Combs 3120e64570 wslua: Fix the build.
Fix

    wireshark\epan\wslua\wslua_proto_field.c(423,29): error C2220: the following warning is treated as an error [wireshark\build\epan\wslua\wslua.vcxproj]
    wireshark\epan\wslua\wslua_proto_field.c(423,29): error C2220:             mask = (guint64)wslua_optguint32(L, idx, default_value); [wireshark\build\epan\wslua\wslua.vcxproj]
    wireshark\epan\wslua\wslua_proto_field.c(423,29): error C2220:                             ^ [wireshark\build\epan\wslua\wslua.vcxproj]
    wireshark\epan\wslua\wslua_proto_field.c(423,29): warning C4244: 'function': conversion from 'guint64' to 'lua_Number', possible loss of data [wireshark\build\epan\wslua\wslua.vcxproj]
    wireshark\epan\wslua\wslua_proto_field.c(423,29): warning C4244:             mask = (guint64)wslua_optguint32(L, idx, default_value); [wireshark\build\epan\wslua\wslua.vcxproj]
    wireshark\epan\wslua\wslua_proto_field.c(423,29): warning C4244:                             ^ [wireshark\build\epan\wslua\wslua.vcxproj]

on Windows and

    wireshark/epan/wslua/wslua_proto_field.c:1462:48: error: format specifies type 'unsigned long' but the argument has type 'guint64' (aka 'unsigned long long') [-Werror,-Wformat]
                                             f->vs,f->mask,f->blob);
                                                   ^~~~~~~
    wireshark/wsutil/wmem/wmem_strutl.h:51:56: note: expanded from macro 'ws_strdup_printf'
    #define ws_strdup_printf(...) wmem_strdup_printf(NULL, __VA_ARGS__)
                                                       ^~~~~~~~~~~

on macOS.
2023-01-04 09:54:52 -08:00
Nardi Ivan e6e3a91696 WSLUA: allow 64 bits bitmask for ProtoField objects
Mask might be specified using a (Lua) number, a string or a UInt64
object.

It is useful to handle 64 bit bitfields.
2023-01-04 14:32:23 +00:00
Gerald Combs fbadb8c785 wslua: Capitalize words in our markup.
Capitalize words in our markup instead of depending on make-wsluarm.pl.
Add a single space after "Mode:".
2022-07-20 14:52:40 -07:00
Gerald Combs 56a9666a3a wslua: Fix our argument definitions.
Make sure our argument definitions match their corresponding function
names.
2022-07-19 18:53:11 +00:00
Chuck Craft 39fc49b792 wsdg: escape tick marks after backtick; fix typo 2022-06-22 18:55:27 -05:00
Pascal Quantin adca11dd5c range_string: follow-up of 893290c 2022-01-05 20:34:15 +00:00
João Valverde a566076839 epan: Move time display types to field_display_e
This makes it easier to understand the code, avoids conflicts
and ugly and unnecessary casts.

The field display enum has evolved over time from integer types
to a type generic parameter.
2021-12-27 22:31:31 +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 19dcb725b6 epan: Remove STR_ASCII and STR_UNICODE
These display bases work to replace unprintable characters so the
name is a misnomer. In addition they are the same option and this
display behaviour is not something that is configurable.

This does not affect encodings because all our internal text strings
need to be valid UTF-8 and the source encoding is specified using
ENC_*.

Remove the assertion for valid UTF-8 in proto.c because
tvb_get_*_string() must return a valid UTF-8 string, always, and we
don't need to assert that, it is expensive.
2021-12-03 04:35:56 +00:00
Gerald Combs 87b84b7813 Lua is a proper name. Fix its capitalization. 2021-11-11 01:08:51 +00:00
Guy Harris b61fd6d76a dfilter, ftypes: get rid of FT_PCRE.
It's not a valid field type, it's only a hack to support regular
expression matching in packet-matching expressions.

Instead, in the packet-matching code, have a separate syntax tree type
for Perl-compatible regular expressions, and a separate instruction to
load one into a register, and have the "matching" operator for field
types take a GRegex * as the second argument.
2021-03-21 03:27:44 -07:00
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
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 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
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
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
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
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
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
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
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 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
Stig Bjørlykke 0837dd23ec Lua: Add absolute time base values
Add ABSOLUTE_TIME_* defines to the base table in init.lua for use
in ProtoField.absolute_time.

Change-Id: I5c99eafdac97655d71fd4f3374294cd587afaf0a
Reviewed-on: https://code.wireshark.org/review/20543
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2017-03-15 18:44:44 +00:00
Stig Bjørlykke 0156f22c62 Lua: Merge sep and str tables into base
Also add documentation strings to the base values.

Change-Id: I00ac8f154fdd0382106ed27d740e16956520be97
Reviewed-on: https://code.wireshark.org/review/20554
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2017-03-15 17:32:30 +00:00
Stig Bjørlykke 17953ceea3 Lua: Check for no table in ProtoField unit string
When using base.UNIT_STRING in a ProtoField the table must be given.

Change-Id: Ie4beb93b5597a97a99939ef2c60a1ee7ece328f2
Reviewed-on: https://code.wireshark.org/review/20542
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2017-03-14 20:40:07 +00:00
Stig Bjørlykke c899dd57ff Lua: Improve base checking for signed integer
Check base value for signed integer before unsigned to avoid a case
where the valid bases for a unsigned integer is presented in a error
message when a signed type is used.

Change-Id: Idfb87597779652e32adceacad220d748afda5e85
Reviewed-on: https://code.wireshark.org/review/20541
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2017-03-14 15:12:36 +00:00
Stig Bjørlykke f1d0533ee1 Lua: Base must be base.DEC or base.UNIT_STRING for signed integer
Reject ProtoField signed integer types with base other than base.DEC
and base.UNIT_STRING.  Update documentation for this.

Bug: 13484
Change-Id: I55a636c89704e96a598f1f185faabd8ad13d96f1
Reviewed-on: https://code.wireshark.org/review/20533
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2017-03-13 21:34:59 +00:00
Stig Bjørlykke e9b4153f29 Lua: Add string types and byte seperators support.
Add handling of STR_ASCII and STR_UNICODE as base types for string
and stringz.  Add handling of SEP_DOT, SEP_DASH, SEP_COLON and
SEP_SPACE for bytes and uint_bytes.  Add SEP_NONE for completeness.

Change-Id: Ida46c215fee7ec7132ec91ab5dd6cb3de4628920
Reviewed-on: https://code.wireshark.org/review/19337
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2016-12-20 13:32:15 +00:00
Stig Bjørlykke bd0fa39c7b Lua: Remove an obsolete comment.
Change-Id: I6a946eb44f4a574d6d9add3604b2dac924c33a9f
Reviewed-on: https://code.wireshark.org/review/19361
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2016-12-20 12:33:42 +00:00
Stig Bjørlykke d4eeeaf6d4 Lua: Add unit names support.
Add support for using unit names in ProtoField integer types by
using base.UNIT_STRING.

Add unit name table argument in ProtoField.float() and
ProtoField.double() (and made backward compatibility).

The use of base.UNIT_STRING is not really the best API for adding
unit names in Lua, but is the simples solution without adding new
arguments to ProtoField.

Change-Id: Ib5d064480cffd970a41db1764440642f6c593bb2
Reviewed-on: https://code.wireshark.org/review/19313
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2016-12-20 10:36:31 +00:00
Stig Bjørlykke 2612f23ad2 Lua: Fix some memory leaks in error paths.
Because luaL_argerror() does a longjmp all memory free must be done
before calling this.

Also rewrote true_false_string_from_table() to be a bit simpler
and to give argument error when too many strings in the table.

Change-Id: Ied0fa468f1274155c746fe2e086dacf1a8582b08
Reviewed-on: https://code.wireshark.org/review/19325
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2016-12-18 20:10:43 +00:00
Guy Harris 0cb44e4277 Handle FT_CHAR, and report unsupported types as such.
FT_CHAR is straightforward to support.

Split the list of "invalid" types into a list of "unsupported" types and
a short list of "invalid" types, containing FT_PCRE (which isn't a valid
type for a field) and "everything else".  Add FT_IEEE_11073_SFLOAT and
FT_IEEE_11073_FLOAT to the "unsupported" list.

Flag the whole unsupported list as just "not handled yet".

Change-Id: I62d2d7eead53377e4e601594a035b4395fdbeead
Reviewed-on: https://code.wireshark.org/review/18979
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-11-29 03:17:37 +00:00
Peter Wu f6e223c895 wslua: Drop unused "push_code" macro parameter
Reduce noise, no caller has used this parameter since its introduction.
Msotly automated regex search and replace.

Change-Id: I4b1180bfee8544b38d19c9c440ff5b9b0dc080b2
Reviewed-on: https://code.wireshark.org/review/14790
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2016-06-14 18:32:51 +00:00
Stig Bjørlykke bfac764797 Lua: Cleanup ProtoField_time
Reverted some unneeded changes from 7f074364 because it's currently
only used for FT_ABSOLUTE_TIME.

Also fixed some small indent issues.

Change-Id: I923e35bf8ad4e991518bee973b87d4be06137463
Reviewed-on: https://code.wireshark.org/review/12539
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2015-12-14 05:19:59 +00:00
Stig Bjørlykke b031e538f7 Lua: Check for empty name in ProtoField
The check in tmp_fld_check_assert() does terminate with g_error
if given an empty string as name, so we have to check for this.

Change-Id: I084e3e715bd319484a52f60ef90c1a2aea30df1b
Reviewed-on: https://code.wireshark.org/review/12534
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2015-12-11 16:56:43 +00:00
Stig Bjørlykke 561bcff027 Lua: Fixed some argument # in argument errors.
Change-Id: I1dba41c9f129d368096dd69a0f40fa2164311124
Reviewed-on: https://code.wireshark.org/review/11852
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2015-11-15 22:05:51 +00:00
Stig Bjørlykke a8e774034b Lua: Check for nil valuestring for integer fields.
Added a check for nil valuestring for all ProtoField integer types
to avoid lookup when argument is not set.

Change-Id: Ib4c016b69ee77dbea4bb83ac93c0d9ae9f48f236
Reviewed-on: https://code.wireshark.org/review/11845
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2015-11-15 19:56:38 +00:00
Stig Bjørlykke e6b5f015e2 Lua: Added support for ProtoField framenum type.
Change-Id: I1d4cddd4026f08416005f2b3212536b3984d1a8d
Reviewed-on: https://code.wireshark.org/review/11834
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2015-11-15 18:33:16 +00:00
Hadriel Kaplan 8fd719731b Lua: add FT_PROTOCOL as a ProtoField type
Bug: 11450
Change-Id: Ic77ddd193246c0202efcc9c11e61e8f6f85329c5
Reviewed-on: https://code.wireshark.org/review/10087
Petri-Dish: Hadriel Kaplan <hadrielk@yahoo.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Hadriel Kaplan <hadrielk@yahoo.com>
2015-08-18 03:50:58 +00:00
Stig Bjørlykke 5f13933ddb Lua: Free true_false_string values at reload
Change-Id: I8ab194bf094e82f08ddafb0a1451aec42989b93d
Reviewed-on: https://code.wireshark.org/review/10044
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2015-08-15 17:26:54 +00:00
Stig Bjørlykke 7833b93c66 Free all hfi->strings in free_deregister_field
Change-Id: I6fe78266a2e881fa80e1e3a3423b685d3c1764de
Reviewed-on: https://code.wireshark.org/review/10029
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2015-08-14 11:47:25 +00:00
Stig Bjørlykke ecc4f756bd Added Reload Lua plugins.
This is initial support for reloading Lua plugins without
restarting the application.

Still todo:
- Deregister FileHandlers
- Support deregister ProtoField with existing abbrev (same_name_hfinfo)
- Add a progress dialog when reloading many plugins
- Search for memory leakages in wslua functions

Change-Id: I48870d8741251705ca15ffe1068613fcb0cb18c1
Reviewed-on: https://code.wireshark.org/review/5028
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2015-08-11 12:09:07 +00:00
Hadriel Kaplan 0caf0616ba Lua: split up wslua files into class-based files
The size of some of the wslua source files has grown large, and it's hard
to quickly find things. So split them up based on class name, as much as
seems reasonable. Also have the make-wsluarm.pl Perl script handle this.

Change-Id: Ib495ec5c2a4df90495c0a05504856288a0b09213
Reviewed-on: https://code.wireshark.org/review/9579
Petri-Dish: Hadriel Kaplan <hadrielk@yahoo.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Hadriel Kaplan <hadrielk@yahoo.com>
2015-07-12 02:08:24 +00:00