Commit Graph

8 Commits

Author SHA1 Message Date
João Valverde e7f439bc2f Convert capture file regex search to PCRE2.
Replace the use of the obsolete GRegex with PCRE2.

Fixes a crash reported in issue #17500.
2022-07-27 11:21:03 +00:00
João Valverde 47348ae598 dfilter: Add support for literal strings with null bytes
Before:
    Filter: frame matches "abc\x00def"
    dftest: \x00 (NUL byte) cannot be used with a regular string.
    	frame matches "abc\x00def"
    	                  ^~~~
    Filter: _ws.ftypes.string == "a string with a \0 byte"
    dftest: \0 (NUL byte) cannot be used with a regular string.
    	_ws.ftypes.string == "a string with a \0 byte"
    	                                      ^~

After:
    Filter: frame matches "abc\x00def"

    Syntax tree:
     0 TEST_MATCHES:
       1 FIELD(frame)
       1 PCRE(abc\0def)

    Instructions:
    00000 READ_TREE		frame -> reg#0
    00001 IF_FALSE_GOTO	3
    00002 ANY_MATCHES	reg#0 matches abc\0def
    00003 RETURN

    Filter: _ws.ftypes.string == "a string with a \0 byte"

    Syntax tree:
     0 TEST_ANY_EQ:
       1 FIELD(_ws.ftypes.string)
       1 FVALUE("a string with a \0 byte" <FT_STRING>)

    Instructions:
    00000 READ_TREE		_ws.ftypes.string -> reg#0
    00001 IF_FALSE_GOTO	3
    00002 ANY_EQ		reg#0 == "a string with a \0 byte" <FT_STRING>
    00003 RETURN

Fixes issue #16156.
2022-06-21 15:10:08 +00:00
João Valverde de103394fe dfilter: Make regex matches case insensitive by default 2022-06-08 12:17:22 +01:00
João Valverde 36d5aad962 wsutil: Split ws_regex_matches() into two functions
Split ws_regex_matches() into two functions with better semantics
and remove the WS_REGEX_ZERO_TERMINATED symbol.

ws_regex_matches() matches zero terminated strings.

ws_regex_matches_length() matches a string length in code units.
2021-12-21 00:40:02 +00:00
João Valverde fb0e1a4907 regex: Remove requirement for ssize_t
The type ssize_t is not available on Windows. Because this is
used in the public API we must provide a definition for it.
To avoid having to add a header to fix this use a size_t in
the API instead, and assign SIZE_MAX to represent a null
terminated string.
2021-12-13 23:57:32 +00:00
João Valverde b30a2112e8 regex: Prefer C99/POSIX types
Replace 'gssize' with 'ssize_t'.

Add a CMake configure check for ssize_t.

Fix missing "config.h" includes.
2021-11-15 02:41:59 +00:00
João Valverde b59980bbff regex: Add a diagnostic message
Add a debug log message if pcre2_match() errors out.

Minor optimization with the use of pcre2_match_data_create().

Minor cleanup.
2021-11-14 23:05:53 +00:00
João Valverde 274531820a Move regex code to wsutil 2021-11-14 21:00:59 +00:00