Commit Graph

40 Commits

Author SHA1 Message Date
João Valverde db85625af9 dfilter: Rewrite ws_assert_magic() again 2021-10-08 04:01:24 +00:00
João Valverde e4e0b97082 dfilter: Use wslog with ws_assert_magic() 2021-10-06 15:44:48 +00:00
João Valverde 8c5a4f9100 dfilter: Replace node accessor macros with functions
Replace macro magic to improve ease of comprehension and maintenance.
2021-10-06 15:44:48 +00:00
João Valverde a7242733a4 dfilter: Fix ws_assert_magic() macro
We need to use WS_DISABLE_DEBUG, not WS_DEBUG.

Fixes 0e50979b3f.

Rename some lingering assert_magic() references.
2021-10-06 15:44:48 +00:00
João Valverde 4804c1224d dfilter: Use syntax tree node replacement semantics
Instead of using 3 operations (new + free + reassign_to_parent) to transform
the tree use a simpler single replace operation instead.

This also avoids having to manually copy token values.

The set search and replace method is now obsolete.
2021-10-06 10:34:21 +00:00
João Valverde a940318f37 dfilter: Minor grammar fixups
Clean up syntax error code. TEST and SET are never returned by
the tokenizer.

Remove unnecessary range_body() grammar element. Fix a comment.

Move the stnode_token_value() function to its proper place.
2021-10-05 17:56:21 +01:00
João Valverde db18865e55 dfilter: Save token value to syntax tree
When parsing we save the token value to the syntax tree. This is
useful for better error reporting. Use it to report an invalid
entity for the slice operation. Before only the memory location
was reported, which is not a good error message.

Before:
  % dftest '"01:02:03:04"[0:3] == foo'
  Filter: ""01:02:03:04"[0:3] == foo"
  dftest: Range is not supported for entity <0x7f6c84017740> of type STRING

After:
  % dftest '"01:02:03:04"[0:3] == foo'
  Filter: ""01:02:03:04"[0:3] == foo"
  dftest: Range is not supported for entity 01:02:03:04 of type STRING

When creating a new node from an old one we need to copy the token
value. Simple tokens such as RBRACKET, COMMA and COLON are
not part of the AST and don't have an associated semantic value.
2021-10-01 16:04:37 +00:00
João Valverde 487e2b6bc3 dfilter: Remove unnecessary log activation check
Use log_write_always_full() instead of ws_log() to avoid a useless
activation check.

Rename stnode_log() to log_stnode() for consistency.
2021-10-01 16:04:37 +00:00
João Valverde b4af7c52a5 dfilter: Add a flags member to the syntax tree node
Use it to record "inside parenthesis".
2021-09-30 17:03:55 +00:00
João Valverde 0e7ba54d98 dfilter: Clean up handling of "deprecated" tokens
Pass the deprecated data struture to the scanner and insert the deprecated
tokens there. This avoids having to keep a dedicated syntax node field
for this.

Pass the deprecated argument in dfwork_t instead of in a separate
argument. This is less cumbersome than adding an extra argument
to every level of the semantic checker.
2021-09-30 17:26:19 +01:00
João Valverde 3ea2a61f2a dfilter: Display syntax tree for debugging
Use wslog to output debug information. Being able to control
it at runtime is a big advantage.

We extend the syntax tree nodes with a method to return a
canonical string representation.

Add a routine to walk the tree and return an textual representation
for debugging purposes.
2021-09-30 16:29:11 +01: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
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
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
Guy Harris d7fe514fc0 Improve support for single-character fields and filter expressions.
Add an FT_CHAR type, which is like FT_UINT8 except that the value is
displayed as a C-style character constant.

Allow use of C-style character constants in filter expressions; they can
be used in comparisons with all integral types, and in "contains"
operators.

Use that type for some fields that appear (based on the way they're
displayed, or on the use of C-style character constants in their
value_string tables) to be 1-byte characters rather than 8-bit numbers.

Change-Id: I39a9f0dda0bd7f4fa02a9ca8373216206f4d7135
Reviewed-on: https://code.wireshark.org/review/17787
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-09-19 02:51:13 +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
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
Chris Maynard 2fd6bb79ea Trivial: Spaces -> tabs
svn path=/trunk/; revision=54004
2013-12-13 00:08:16 +00:00
Jakub Zawadzki c6669a3c63 dfilter: report warning if OR and AND logic operands are mixed without parentheses.
svn path=/trunk/; revision=51247
2013-08-10 17:49:28 +00:00
Anders Broman 089dfcd108 From beroset:
remove C++ incompatibilities 
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8416

svn path=/trunk/; revision=48424
2013-03-19 19:02:25 +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 addf9236dc Support multiple relation test without logic and (python-like)
Like: 
  a == b == c 
  or 
  a < b <= c <= d < e 

Real life example:
  6660 <= tcp.port <= 6669

Just syntactic sugar, this is *NOT* optimized.

svn path=/trunk/; revision=43353
2012-06-19 12:12:41 +00:00
Anders Broman a009cc0605 Doxygen changes.
svn path=/trunk/; revision=33990
2010-08-29 10:47:38 +00:00
Kovarththanan Rajaratnam cd49063473 Revert r29614 until I figure out why buildbot doesn't like it
svn path=/trunk/; revision=29615
2009-08-29 07:53:48 +00:00
Kovarththanan Rajaratnam cc948586bf Use G_STRINGIFY/G_PASTE
svn path=/trunk/; revision=29614
2009-08-29 06:42:23 +00:00
Stig Bjørlykke ee8b8b0ad7 Hmmm. Second try to fix the const problems.
svn path=/trunk/; revision=24238
2008-01-31 23:10:09 +00:00
Stig Bjørlykke dc5b4a8239 Removed a const to make it compile.
svn path=/trunk/; revision=24237
2008-01-31 22:31:01 +00:00
Gerald Combs a4a1f2a69e Make the "!="/"ne" change compile under Windows.
svn path=/trunk/; revision=24234
2008-01-31 20:18:07 +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
Ronnie Sahlberg 89f022b12b name change
svn path=/trunk/; revision=18197
2006-05-21 05:12:17 +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 fd9291e9c6 Move declaration of sttype_register_* functions from
syntax-tree.c to syntax-tree.h.

This fixes some warning of type
sttype-integer.c:33: warning: no previous declaration for
                                'sttype_register_integer'


svn path=/trunk/; revision=15011
2005-07-23 06:49:07 +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
Guy Harris e1e690ff3a From Graeme Hewson:
Use gint32 instead of guint32 for node data.

Fix up some other signed-vs-unsigned issues in the display filter
parser and lexical analyzer.

svn path=/trunk/; revision=11085
2004-06-03 07:36:25 +00:00
Gilbert Ramirez 086774b71f Add to the fundamental types passed between the scanner and the parser.
Besides "STRING", there is now "UNPARSED_STRING", where the distinction
is that "STRING" was a double-quoted string and "UNPARSED_STRING" is just
a sequence of characters that the scanner didn't know how to scan/parse,
so it's up to the Ftype to parse it.

This gives us more flexibility and prepares the dfilter parsing engine
for the upcoming addition of the "contains" operator.

In the process of doing this, I also re-did the double-quoted string
support in the scanner, so that instead of the naively-simple support we
used to have, double-quoted strings now can have embedded dobule-quotes,
embedded octal sequences, and embedded hexadecimal sequences:
    "\""    embedded double-quote
    "\110"  embedded octal
    "\x48"  embedded hex

Enhance the dfilter unit test script to be able to run a single collection
of tests instead of having to run all of them all the time.

svn path=/trunk/; revision=8083
2003-07-25 03:44:05 +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
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 96e0398fc6 Grumble, grumble. I forgot to add the license comment at the top
of these files.

svn path=/trunk/; revision=2968
2001-02-01 20:31:21 +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