Commit Graph

45 Commits

Author SHA1 Message Date
João Valverde e8800ff3c4 dfilter: Add a thin encapsulation layer for REs 2021-10-18 12:09:36 +00:00
João Valverde 0e50979b3f Replace g_assert() with ws_assert() 2021-06-19 01:23:31 +00:00
Guy Harris b61fd6d76a dfilter, ftypes: get rid of FT_PCRE.
It's not a valid field type, it's only a hack to support regular
expression matching in packet-matching expressions.

Instead, in the packet-matching code, have a separate syntax tree type
for Perl-compatible regular expressions, and a separate instruction to
load one into a register, and have the "matching" operator for field
types take a GRegex * as the second argument.
2021-03-21 03:27:44 -07:00
Guy Harris d78d50d5a1 Move some variables inside the block where they're used.
They're not used outside a block, so move them inside the block.  Also,
they're set before they're used, so don't initialize them when they're
declared.

This should squelch some unreadVariable warnings from cppcheck.
2021-01-20 12:45:46 -08: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 eec3ce3bb2 dfilter: fix memory leaks on dfilter compile errors involving a set
If a display filter contains a set for the set membership operator and
an error occurs, then gen_relation_in() (called via dfw_gencode() will
not take ownership of the set and a memory leak occurs.

Fix this by implementing a free callback for STTYPE_SET nodes which
frees unclaimed data. Add tests to verify the effectiveness, ASAN no
longer complains after this fix.

Bug: 15442
Change-Id: If37cf047660464b2d0304748034d0bc22111e5d6
Reviewed-on: https://code.wireshark.org/review/31758
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-01-28 11:09:35 +00:00
Peter Wu e8e60df4ce dfilter: fix memory leaks if a dfilter fails to compile
A display filter can contain values such as strings, numbers, etc. These
are internally stored in a fvalue_t structure. While compiling a display
filter, it will store a fvalue_t in a node of type STTYPE_FVALUE.

These nodes are created while parsing the dfilter in dfilter_compile().
If the semantic check and conversion (dfw_semcheck()) succeeds, it will
transfer the values of the parsed tree to dfw_gencode(). After that,
dfwork_free will dispose the tree while a compiled dfilter code remains.
When the dfilter code is destroyed, it will free the values too.

However, when dfw_semcheck() fails (for example, due to an illegal
filter such as "len(badname)==1"), it will skip "dfw_gencode()" and
consequently the fvalue data is not transferred nor freed. Fix this by
always freeing the data (unless the data was stolen by dfw_gencode()).

Fixes a memory leak reported for case_dfunction_string::test_fail_2
which was detected by ASAN.

Bug: 15442
Change-Id: I9b1cb613659890c8ddcfa57f11f9d3f61a51a3f9
Reviewed-on: https://code.wireshark.org/review/31757
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-01-28 11:09:17 +00:00
Peter Wu 1ff82572ca dfilter: add range support to set membership operator ("f in {x .. y}")
Allow "tcp.srcport in {1662 1663 1664}" to be abbreviated to
"tcp.srcport in {1662 .. 1664}". The range operator is supported for any
field value which supports the "<=" and "=>" operators and thus works
for integers, IP addresses, etc.

The naive mapping "tcp.srcport >= 1662 and tcp.srcport <= 1664" is not
used because it does not have the intended effect with fields that have
multiple occurrences (e.g. tcp.port). Each condition could be satisfied
by an other value. Therefore a new DVFM instruction (ANY_IN_RANGE) is
added to test the range condition against each individual field value.

Bug: 14180
Change-Id: I53c2d0f9bc9d4f0ffaabde9a83442122965c95f7
Reviewed-on: https://code.wireshark.org/review/26945
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-04-18 03:47:02 +00:00
Dario Lombardo 566d20f444 dfilter: use g_malloc0 to prevent uninitialized memory to be used.
Found by clang.

Change-Id: I89497bd0f32c79f82218c6d254a214364c930eb3
Reviewed-on: https://code.wireshark.org/review/25884
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-02-21 17:14:30 +00:00
Dario Lombardo 55c68ee69c epan: use SPDX indentifiers.
Skipping dissectors dir for now.

Change-Id: I717b66bfbc7cc81b83f8c2cbc011fcad643796aa
Reviewed-on: https://code.wireshark.org/review/25694
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-02-08 19:29:45 +00:00
Michael Mann 1da1f945e2 Fix checkAPI.pl warnings about printf
Many of the complaints from checkAPI.pl for use of printf are when its embedded
in an #ifdef and checkAPI isn't smart enough to figure that out.
The other (non-ifdef) use is dumping internal structures (which is a type of
debug functionality)
Add a "ws_debug_printf" macro for printf to pacify the warnings.

Change-Id: I63610e1adbbaf2feffb4ec9d4f817247d833f7fd
Reviewed-on: https://code.wireshark.org/review/16623
Reviewed-by: Michael Mann <mmann78@netscape.net>
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2016-07-25 04:26:50 +00:00
Jeffrey Smith 80322d88da dfilter: Add membership operator
Added a new relational test: 'x in {a b c}'.  The only LHS entity
supported at this time is a field.  The generated DFVM operations are
equivalent to an OR'ed series of =='s, but with the redundant existence
tests removed.

Change-Id: Iddc89b81cf7ad6319aef1a2a94f93314cb721a8a
Reviewed-on: https://code.wireshark.org/review/10246
Reviewed-by: Hadriel Kaplan <hadrielk@yahoo.com>
Petri-Dish: Hadriel Kaplan <hadrielk@yahoo.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2015-09-11 06:31:33 +00:00
Bill Meier e88a11f5c9 (Trivial) Fix printf-related 'Mismatch on sign' warnings
Found by MSVC2013 Code Analysis

Change-Id: I58063946dd558e98308c87b36eeac0ddbe1a6e79
Reviewed-on: https://code.wireshark.org/review/7045
Reviewed-by: Bill Meier <wmeier@newsguy.com>
2015-02-09 18:57:14 +00:00
Alexis La Goutte 296591399f Remove all $Id$ from top of file
(Using sed : sed -i '/^ \* \$Id\$/,+1 d')

Fix manually some typo (in export_object_dicom.c and crc16-plain.c)

Change-Id: I4c1ae68d1c4afeace8cb195b53c715cf9e1227a8
Reviewed-on: https://code.wireshark.org/review/497
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-03-04 14:27:33 +00:00
Jakub Zawadzki 9cfac1227d Replace hfinfo pointer to same_name_prev, with same_name_prev_id.
svn path=/trunk/; revision=51175
2013-08-06 20:53:47 +00:00
Jakub Zawadzki da170f1d04 Fix bug #8979: Comparing function call and a range in the filter crashes Wireshark
store whole node, don't assume it's always STTYPE_FIELD

svn path=/trunk/; revision=50949
2013-07-27 17:17:15 +00:00
Anders Broman 7ad305365f type drange -> drange_t
explicit casts.

svn path=/trunk/; revision=48083
2013-03-05 06:16:45 +00:00
Jeff Morriss 3729335973 We always HAVE_CONFIG_H so don't bother checking whether we have it or not.
svn path=/trunk/; revision=45016
2012-09-20 01:48:30 +00:00
Evan Huus fc4d43ec42 Add modelines and make indentation consistent.
svn path=/trunk/; revision=44730
2012-09-01 15:12:43 +00:00
Jakub Zawadzki bf81b42e1e Update Free Software Foundation address.
(COPYING will be updated in next commit)

svn path=/trunk/; revision=43536
2012-06-28 22:56:06 +00:00
Jakub Zawadzki 6fff7c61f0 display filter: restore comparision of fields.
like:
  udp.srcport == udp.dstport
  frame.cap_len != frame.len
(probably you can use it for better ones)

part of bug #7263


svn path=/trunk/; revision=43069
2012-06-04 14:45:50 +00:00
Anders Broman 345b48d1ea Try to squelch warnings
svn path=/trunk/; revision=43019
2012-06-03 09:26:15 +00:00
Bill Meier ede51600c7 Don't assign to a variable if the value won't be used: Coverity 817-821.
svn path=/trunk/; revision=36446
2011-04-04 15:31:33 +00:00
Gerald Combs 9703c2bb75 If "!=" or "ne" are used in a display filter, warn the user that the results
may be unexpected.

svn path=/trunk/; revision=24232
2008-01-31 19:50:38 +00:00
Bill Meier b436aeaf5f From Didier Gautheron: Bug #2042: Move constants initialisation at compile time.
svn path=/trunk/; revision=23659
2007-11-28 22:44:37 +00:00
Bill Meier 6d4dda3327 From Didier Gautheron: Bug #2040: Fix up goto at compilation time in gencode.c
svn path=/trunk/; revision=23658
2007-11-28 22:37:33 +00:00
Ronnie Sahlberg 89f022b12b name change
svn path=/trunk/; revision=18197
2006-05-21 05:12:17 +00:00
Anders Broman 0fdfab9fc6 MSVC is picky about assignments in declarations.
svn path=/trunk/; revision=18074
2006-05-02 19:07:38 +00:00
Gilbert Ramirez e3899ed4a4 Add infrastructure for display filter functions.
Add upper() and lower() display filter functions for string fields.

svn path=/trunk/; revision=18071
2006-05-02 14:26:17 +00:00
Jörg Mayer 8433afe23b Albert Chin:
Don't include epan/gdebug.h

Now that epan/gdebug.h is unused: remove it

svn path=/trunk/; revision=15209
2005-08-04 21:09:08 +00:00
Jörg Mayer cd0744efd1 Add includes to fix warnings of type
gencode.c:383: warning: no previous declaration for
                        'dfw_interesting_fields'

svn path=/trunk/; revision=15012
2005-07-23 06:51:57 +00:00
Guy Harris 8a8b883450 Set the svn:eol-style property on all text files to "native", so that
they have LF at the end of the line on UN*X and CR/LF on Windows;
hopefully this means that if a CR/LF version is checked in on Windows,
the CRs will be stripped so that they show up only when checked out on
Windows, not on UN*X.

svn path=/trunk/; revision=11400
2004-07-18 00:24:25 +00:00
Olivier Biot 1791f84919 First attempt at "bitwise AND" display filter operator.
Document how a display operator can be added.

svn path=/trunk/; revision=10250
2004-02-27 12:00:32 +00:00
Gilbert Ramirez 55a6251e7c From Olivier Biot
New "matches" operater in display filter language. Uses PCRE.

If a "matches" operator is found in a dfilter
while libpcre has not been used to build the binary, then an
exception is thrown after using dfilter_fail() to set an apporporiate
error message.

svn path=/trunk/; revision=9182
2003-12-06 16:35:20 +00:00
Gilbert Ramirez 52338a3baf Add a "contains" operator for byte-strings, strings, and tvbuffs (protocols).
The search uses a naive approach; more work is required to add a
Boyer-Moore Search algorithm.

svn path=/trunk/; revision=8280
2003-08-27 15:23:11 +00:00
Guy Harris b18f9bad07 Handle the case of a comparison between two ranges (or, at least, don't
dump core if the user tries it).

svn path=/trunk/; revision=7875
2003-06-13 10:03:25 +00:00
Gilbert Ramirez ddc7b4597b Fix a problem when using the same field more than once in a display
filter, as in "ip.src == x.x.x.x || ip.src == y.y.y.y". My previous
change to allow filtering on multiple fields of the same name moved
some code into the wrong block within the function, causing the error.

svn path=/trunk/; revision=6544
2002-11-01 17:37:25 +00:00
Gilbert Ramirez 1ba73660c0 Make the dfilter code support multiple header_field_info's with
the same name (abbreviation). Thus, if multiple protocols or fields
are registered with the same name, you can still filter on the name
and have the filtering work as expected.

svn path=/trunk/; revision=6434
2002-10-16 16:32:59 +00:00
Jörg Mayer 48be4e530d Removed trailing whitespaces from .h and .c files using the
winapi_cleanup tool written by Patrik Stridvall for the wine
project.

svn path=/trunk/; revision=6116
2002-08-28 20:41:00 +00:00
Guy Harris 52fb615708 From Joerg Mayer: get rid of "-Wno-unused" flag in some configure
scripts, and check in changes to add _U_ to some unused arguments (some
other should perhaps be used, so we leave the _U_ out so that the
warnings serve as a reminder to check those).

svn path=/trunk/; revision=4848
2002-03-02 20:51:46 +00:00
Guy Harris ee5ca25d31 Include files from the "epan" directory and subdirectories thereof with
"epan/..." pathnames, so as to avoid collisions with header files in any
of the directories in which we look (e.g., "proto.h", as some other
package has its own "proto.h" file which it installs in the top-level
include directory).

Don't add "-I" flags to search "epan", as that's no longer necessary
(and we want includes of "epan" headers to fail if the "epan/" is left
out, so that we don't re-introduce includes lacking "epan/").

svn path=/trunk/; revision=4586
2002-01-21 07:37:49 +00:00
Gilbert Ramirez 791f5774d0 Provide for per-protocol-tree data in the proto_tree code.
Put a hash-table of "interesting" fields in the per-proto-tree data.
The dfilter code records which fields/protocols are "interesting" (by which
I mean, their value or existence is checked). Thus, the proto_tree routines
can create special arrays of field_info*'s that are ready for the dfilter
engine to use during a filter operation.

Also store the "proto_tree_is_visible" boolean, renamed "visible", in
the per-proto-tree data.

Move epan_dissect_t to its own header file to make #include dependencies
easier to handle.

Provide epan_dissect_fill_in_columns(), which accepts just the epan_dissect_t*
as an argument.

epan_dissect_new() needs to be followed by epan_dissect_run() for the
dissection to actually take place. Between those two calls,
epan_dissect_prime_dfilter() can be run 0, 1, or multiple times in order to
prime the empty proto_tree with the "intersesting" fields from the dfilter_t.

svn path=/trunk/; revision=4422
2001-12-18 19:09:08 +00:00
Gilbert Ramirez 2a50f8af4f Add Ed Warnicke's drange code to the new dfilter system.
Not supported yet: [i-j] (offset-offset)
Supported:
	[i]	index
	[i:j]	offset:length
	[:j]	0:offset
	[i:]	offset:end
	[x,y]	concatenation of slices

svn path=/trunk/; revision=3080
2001-02-27 19:23:30 +00:00
Gilbert Ramirez ea7ef0fb0c Remove unused variable and add copyright and RCS ID.
svn path=/trunk/; revision=3013
2001-02-11 03:12:46 +00:00
Gilbert Ramirez 8f1fff2e6a Create a more modular type system for the FT_* types. Put them
into epan/ftypes.

Re-write display filter routines using Lemon parser instead of yacc.
Besides using a different tool, the new grammar is much simpler, while
the display filter engine itself is more powerful and more easily extended.

Add dftest executable, to test display filter "bytecode" generation.
Add option to "configure" to build dftest or randpkt, both of which are not
built by default.

Implement Ed Warnicke's ideas about dranges in the new display filter and
ftype code.

Remove type FT_TEXT_ONLY in favor of FT_NONE, and have protocols registered
as FT_PROTOCOL. Thus, FT_NONE is used only for simple labels in the proto tree,
while FT_PROTOCOL is used for protocols. This was necessary for being
able to make byte slices (ranges) out of protocols, like "frame[0:3]"

Win32 Makefile.nmake's will be added tonight.

svn path=/trunk/; revision=2967
2001-02-01 20:21:25 +00:00