From b9f2e4b7fa091719b93f6256ac34be8e32bd8e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Valverde?= Date: Fri, 12 Nov 2021 10:11:25 +0000 Subject: [PATCH] Make PCRE2 a required dependency --- CMakeLists.txt | 10 +------ CMakeOptions.txt | 1 - cmakeconfig.h.in | 2 +- docbook/release-notes.adoc | 7 ++--- epan/dfilter/sttype-pointer.c | 4 +-- epan/epan.c | 22 --------------- epan/ftypes/ftypes.c | 51 +++++------------------------------ epan/ftypes/ftypes.h | 3 --- ui/CMakeLists.txt | 13 +++++++-- ui/version_info.c | 13 +++++++++ 10 files changed, 39 insertions(+), 87 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 77f718bc81..3ed686c7cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1194,6 +1194,7 @@ reset_find_package(CARES) find_package(CARES "1.5.0" REQUIRED) find_package(LEX REQUIRED) find_package(Perl REQUIRED) +find_package(PCRE2 REQUIRED) if(CMAKE_VERSION VERSION_LESS "3.12") # Locate the Python interpreter. Finds the wrong (Python 2) version if: @@ -1288,9 +1289,6 @@ ws_find_package(SMI ENABLE_SMI HAVE_LIBSMI) # Support for TLS decryption using RSA private keys. ws_find_package(GNUTLS ENABLE_GNUTLS HAVE_LIBGNUTLS "3.3.0") -# PCRE2 -ws_find_package(PCRE2 ENABLE_PCRE2 HAVE_PCRE2) - # Kerberos ws_find_package(KERBEROS ENABLE_KERBEROS HAVE_KERBEROS) @@ -3775,12 +3773,6 @@ configure_file( add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) -if(NOT HAVE_PCRE2) - message(WARNING "Building without PCRE2 is not recommended. \ -Regular expression matching will be unavailable." - ) -endif() - # # Editor modelines - https://www.wireshark.org/tools/modelines.html # diff --git a/CMakeOptions.txt b/CMakeOptions.txt index 286daa5c92..25cd8fe6f3 100644 --- a/CMakeOptions.txt +++ b/CMakeOptions.txt @@ -97,7 +97,6 @@ option(ENABLE_NGHTTP2 "Build with HTTP/2 header decompression support" ON) option(ENABLE_LUA "Build with Lua dissector support" ON) option(ENABLE_SMI "Build with libsmi snmp support" ON) option(ENABLE_GNUTLS "Build with RSA decryption support" ON) -option(ENABLE_PCRE2 "Build with regular expression support" ON) if(WIN32) option(ENABLE_WINSPARKLE "Enable automatic updates using WinSparkle" ON) endif() diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in index 90809058c7..a9327993b0 100644 --- a/cmakeconfig.h.in +++ b/cmakeconfig.h.in @@ -92,7 +92,7 @@ #cmakedefine HAVE_KERBEROS 1 /* Define to use PCRE2 library */ -#cmakedefine HAVE_PCRE2 1 +#define HAVE_PCRE2 1 /* Define to use nghttp2 */ #cmakedefine HAVE_NGHTTP2 1 diff --git a/docbook/release-notes.adoc b/docbook/release-notes.adoc index 727202e068..147e20d64a 100644 --- a/docbook/release-notes.adoc +++ b/docbook/release-notes.adoc @@ -16,6 +16,8 @@ It is used for troubleshooting, analysis, development and education. == What’s New +* The PCRE2 library (https://www.pcre.org/) is now a required dependency to build Wireshark. + Many improvements have been made. See the “New and Updated Features” section below for more details. @@ -119,9 +121,8 @@ The following features are new (or have been significantly updated) since versio ** Adds support for some additional character escape sequences in double quoted strings. Besides octal and hex byte specification the following C escape sequences are now supported with the same meaning: \a, \b, \f, \n, \r, \t, \v. Previously they were only supported with character constants. Note that unrecognized escape sequences are treated as a literal character. This has not changed from previous versions. -** The display filter engine now uses PCRE2 instead of GRegex (GLib bindings to the older end-of-life PCRE library). The PCRE2 library (https://www.pcre.org/) - is required to support pattern matching using regular expressions. PCRE2 is compatible with PCRE so the user-visible changes should be minimal. Some - exotic patterns may now be invalid and require rewriting. +** The display filter engine now uses PCRE2 instead of GRegex (GLib bindings to the older end-of-life PCRE library). PCRE2 is compatible with PCRE so + the user-visible changes should be minimal. Some exotic patterns may now be invalid and require rewriting. * Corrected calculation of mean jitter in RTP Stream Analysis dialog and IAX2 Stram Analysis dialog diff --git a/epan/dfilter/sttype-pointer.c b/epan/dfilter/sttype-pointer.c index 9c2e91af6f..184831c74f 100644 --- a/epan/dfilter/sttype-pointer.c +++ b/epan/dfilter/sttype-pointer.c @@ -65,11 +65,11 @@ field_tostr(const void *data, gboolean pretty _U_) } static char * -pcre_tostr(const void *data, gboolean pretty) +pcre_tostr(const void *data, gboolean pretty _U_) { const fvalue_regex_t *pcre = data; - return g_strdup(fvalue_regex_tostr(pcre, pretty)); + return g_strdup(fvalue_regex_pattern(pcre)); } void diff --git a/epan/epan.c b/epan/epan.c index 1beb8d8101..85a02ed4ac 100644 --- a/epan/epan.c +++ b/epan/epan.c @@ -97,10 +97,6 @@ #include #endif -#ifdef HAVE_PCRE2 -#include -#endif - #ifndef _WIN32 #include #endif @@ -809,13 +805,6 @@ epan_get_compiled_version_info(GString *str) g_string_append(str, ", without MaxMind DB resolver"); #endif /* HAVE_MAXMINDDB */ - /* PCRE2 */ -#ifdef HAVE_PCRE2 - g_string_append(str, ", with PCRE2"); -#else - g_string_append(str, ", without PCRE2"); -#endif /* HAVE_PCRE2 */ - /* nghttp2 */ #ifdef HAVE_NGHTTP2 g_string_append(str, ", with nghttp2 " NGHTTP2_VERSION); @@ -883,17 +872,6 @@ epan_get_runtime_version_info(GString *str) /* Gcrypt */ g_string_append_printf(str, ", with Gcrypt %s", gcry_check_version(NULL)); - /* PCRE2 */ -#ifdef HAVE_PCRE2 - int pcre2_size = pcre2_config(PCRE2_CONFIG_VERSION, NULL); - if (pcre2_size > 0 && pcre2_size <= 255) { - char *pcre2_str = g_malloc0(pcre2_size + 1); - pcre2_config(PCRE2_CONFIG_VERSION, pcre2_str); - g_string_append_printf(str, ", with PCRE2 %s", pcre2_str); - g_free(pcre2_str); - } -#endif /* HAVE_PCRE2 */ - /* nghttp2 */ #if NGHTTP2_VERSION_AGE >= 1 nghttp2_info *nghttp2_ptr = nghttp2_version(0); diff --git a/epan/ftypes/ftypes.c b/epan/ftypes/ftypes.c index 9fe3aaa58e..fbfc2aa8c2 100644 --- a/epan/ftypes/ftypes.c +++ b/epan/ftypes/ftypes.c @@ -11,14 +11,12 @@ #include "ftypes-int.h" #include -#ifdef HAVE_PCRE2 +#include #include -#endif struct _fvalue_regex_t { - void *code; + pcre2_code *code; char *pattern; - char *repr_debug; }; /* Keep track of ftype_t's via their ftenum number */ @@ -723,7 +721,6 @@ fvalue_matches(const fvalue_t *a, const fvalue_regex_t *b) return a->ftype->cmp_matches(a, b); } -#ifdef HAVE_PCRE2 static pcre2_code * _pcre2_compile(const char *patt, char **errmsg) { @@ -763,73 +760,39 @@ _pcre2_matches(pcre2_code *code, const char *subj, gssize subj_size) return rc < 0 ? FALSE : TRUE; } -#endif /* HAVE_PCRE2 */ fvalue_regex_t * fvalue_regex_compile(const char *patt, char **errmsg) { - void *code; + ws_return_val_if_null(patt, NULL); -#ifdef HAVE_PCRE2 - code = _pcre2_compile(patt, errmsg); -#else - (void)patt; - code = NULL; - *errmsg = g_strdup("Wireshark was compiled without PCRE2"); -#endif + pcre2_code *code = _pcre2_compile(patt, errmsg); if (code == NULL) return NULL; fvalue_regex_t *re = g_new(fvalue_regex_t, 1); re->code = code; re->pattern = g_strdup(patt); - re->repr_debug = NULL; return re; } gboolean fvalue_regex_matches(const fvalue_regex_t *regex, const char *subj, gssize subj_size) { -#ifdef HAVE_PCRE2 - ws_assert(regex != NULL); + ws_return_val_if_null(regex, FALSE); + ws_return_val_if_null(subj, FALSE); + return _pcre2_matches(regex->code, subj, subj_size); -#else - ws_assert(regex == NULL); - (void)subj; - (void)subj_size; - return FALSE; -#endif } void fvalue_regex_free(fvalue_regex_t *regex) { -#ifdef HAVE_PCRE2 pcre2_code_free(regex->code); -#endif g_free(regex->pattern); - g_free(regex->repr_debug); g_free(regex); } -const char * -fvalue_regex_tostr(const fvalue_regex_t *regex, gboolean pretty) -{ - if (pretty) - return regex->pattern; - - if (regex->repr_debug == NULL) { -#ifdef HAVE_PCRE2 - const char *kind = "PCRE2"; -#else - const char *kind = "not supported"; -#endif - ((fvalue_regex_t *)regex)->repr_debug = - g_strdup_printf("(%s)%s", kind, regex->pattern); - } - return regex->repr_debug; -} - const char * fvalue_regex_pattern(const fvalue_regex_t *regex) { diff --git a/epan/ftypes/ftypes.h b/epan/ftypes/ftypes.h index 598ada370b..0e38d61a09 100644 --- a/epan/ftypes/ftypes.h +++ b/epan/ftypes/ftypes.h @@ -361,9 +361,6 @@ fvalue_regex_matches(const fvalue_regex_t *regex, const char *subj, gssize subj_ void fvalue_regex_free(fvalue_regex_t *regex); -const char * -fvalue_regex_tostr(const fvalue_regex_t *regex, gboolean pretty); - const char * fvalue_regex_pattern(const fvalue_regex_t *regex); diff --git a/ui/CMakeLists.txt b/ui/CMakeLists.txt index a3ca27ac33..22146aa0b2 100644 --- a/ui/CMakeLists.txt +++ b/ui/CMakeLists.txt @@ -101,9 +101,18 @@ if(NOT VCSVERSION_OVERRIDE) add_dependencies(version_info vcs_version) endif() -target_link_libraries(version_info PRIVATE ${ZLIB_LIBRARIES} wsutil) +target_link_libraries(version_info + PRIVATE + wsutil + ${ZLIB_LIBRARIES} + ${PCRE2_LIBRARIES} +) -target_include_directories(version_info SYSTEM PRIVATE ${ZLIB_INCLUDE_DIRS}) +target_include_directories(version_info + SYSTEM PRIVATE + ${ZLIB_INCLUDE_DIRS} + ${PCRE2_INCLUDE_DIRS} +) set_target_properties(ui version_info PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}" diff --git a/ui/version_info.c b/ui/version_info.c index a9a14a6f7b..0621925776 100644 --- a/ui/version_info.c +++ b/ui/version_info.c @@ -25,6 +25,7 @@ #endif #include +#include #ifdef HAVE_ZLIB #include @@ -175,6 +176,9 @@ get_compiled_version_info(void (*prepend_info)(GString *), "GLib (version unknown)"); #endif + /* PCRE2 */ + g_string_append(str, ", with PCRE2"); + g_string_append_printf(str, ", %s", get_zlib_compiled_version_info()); /* Additional application-dependent information */ @@ -410,6 +414,15 @@ get_runtime_version_info(void (*additional_info)(GString *)) g_string_append_printf(str, ", with GLib %u.%u.%u", glib_major_version, glib_minor_version, glib_micro_version); + /* PCRE2 */ + int pcre2_size = pcre2_config(PCRE2_CONFIG_VERSION, NULL); + if (pcre2_size > 0 && pcre2_size <= 255) { + char *pcre2_str = g_malloc0(pcre2_size + 1); + pcre2_config(PCRE2_CONFIG_VERSION, pcre2_str); + g_string_append_printf(str, ", with PCRE2 %s", pcre2_str); + g_free(pcre2_str); + } + /* zlib */ #if defined(HAVE_ZLIB) && !defined(_WIN32) g_string_append_printf(str, ", with zlib %s", zlibVersion());