Make PCRE2 a required dependency

This commit is contained in:
João Valverde 2021-11-12 10:11:25 +00:00
parent 9df5279af7
commit b9f2e4b7fa
10 changed files with 39 additions and 87 deletions

View File

@ -1194,6 +1194,7 @@ reset_find_package(CARES)
find_package(CARES "1.5.0" REQUIRED) find_package(CARES "1.5.0" REQUIRED)
find_package(LEX REQUIRED) find_package(LEX REQUIRED)
find_package(Perl REQUIRED) find_package(Perl REQUIRED)
find_package(PCRE2 REQUIRED)
if(CMAKE_VERSION VERSION_LESS "3.12") if(CMAKE_VERSION VERSION_LESS "3.12")
# Locate the Python interpreter. Finds the wrong (Python 2) version if: # 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. # Support for TLS decryption using RSA private keys.
ws_find_package(GNUTLS ENABLE_GNUTLS HAVE_LIBGNUTLS "3.3.0") ws_find_package(GNUTLS ENABLE_GNUTLS HAVE_LIBGNUTLS "3.3.0")
# PCRE2
ws_find_package(PCRE2 ENABLE_PCRE2 HAVE_PCRE2)
# Kerberos # Kerberos
ws_find_package(KERBEROS ENABLE_KERBEROS HAVE_KERBEROS) ws_find_package(KERBEROS ENABLE_KERBEROS HAVE_KERBEROS)
@ -3775,12 +3773,6 @@ configure_file(
add_custom_target(uninstall add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) 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 # Editor modelines - https://www.wireshark.org/tools/modelines.html
# #

View File

@ -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_LUA "Build with Lua dissector support" ON)
option(ENABLE_SMI "Build with libsmi snmp support" ON) option(ENABLE_SMI "Build with libsmi snmp support" ON)
option(ENABLE_GNUTLS "Build with RSA decryption support" ON) option(ENABLE_GNUTLS "Build with RSA decryption support" ON)
option(ENABLE_PCRE2 "Build with regular expression support" ON)
if(WIN32) if(WIN32)
option(ENABLE_WINSPARKLE "Enable automatic updates using WinSparkle" ON) option(ENABLE_WINSPARKLE "Enable automatic updates using WinSparkle" ON)
endif() endif()

View File

@ -92,7 +92,7 @@
#cmakedefine HAVE_KERBEROS 1 #cmakedefine HAVE_KERBEROS 1
/* Define to use PCRE2 library */ /* Define to use PCRE2 library */
#cmakedefine HAVE_PCRE2 1 #define HAVE_PCRE2 1
/* Define to use nghttp2 */ /* Define to use nghttp2 */
#cmakedefine HAVE_NGHTTP2 1 #cmakedefine HAVE_NGHTTP2 1

View File

@ -16,6 +16,8 @@ It is used for troubleshooting, analysis, development and education.
== Whats New == Whats New
* The PCRE2 library (https://www.pcre.org/) is now a required dependency to build Wireshark.
Many improvements have been made. Many improvements have been made.
See the “New and Updated Features” section below for more details. 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 ** 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 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. 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/) ** 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
is required to support pattern matching using regular expressions. PCRE2 is compatible with PCRE so the user-visible changes should be minimal. Some the user-visible changes should be minimal. Some exotic patterns may now be invalid and require rewriting.
exotic patterns may now be invalid and require rewriting.
* Corrected calculation of mean jitter in RTP Stream Analysis dialog and IAX2 Stram Analysis dialog * Corrected calculation of mean jitter in RTP Stream Analysis dialog and IAX2 Stram Analysis dialog

View File

@ -65,11 +65,11 @@ field_tostr(const void *data, gboolean pretty _U_)
} }
static char * static char *
pcre_tostr(const void *data, gboolean pretty) pcre_tostr(const void *data, gboolean pretty _U_)
{ {
const fvalue_regex_t *pcre = data; const fvalue_regex_t *pcre = data;
return g_strdup(fvalue_regex_tostr(pcre, pretty)); return g_strdup(fvalue_regex_pattern(pcre));
} }
void void

View File

@ -97,10 +97,6 @@
#include <libxml/parser.h> #include <libxml/parser.h>
#endif #endif
#ifdef HAVE_PCRE2
#include <pcre2.h>
#endif
#ifndef _WIN32 #ifndef _WIN32
#include <signal.h> #include <signal.h>
#endif #endif
@ -809,13 +805,6 @@ epan_get_compiled_version_info(GString *str)
g_string_append(str, ", without MaxMind DB resolver"); g_string_append(str, ", without MaxMind DB resolver");
#endif /* HAVE_MAXMINDDB */ #endif /* HAVE_MAXMINDDB */
/* PCRE2 */
#ifdef HAVE_PCRE2
g_string_append(str, ", with PCRE2");
#else
g_string_append(str, ", without PCRE2");
#endif /* HAVE_PCRE2 */
/* nghttp2 */ /* nghttp2 */
#ifdef HAVE_NGHTTP2 #ifdef HAVE_NGHTTP2
g_string_append(str, ", with nghttp2 " NGHTTP2_VERSION); g_string_append(str, ", with nghttp2 " NGHTTP2_VERSION);
@ -883,17 +872,6 @@ epan_get_runtime_version_info(GString *str)
/* Gcrypt */ /* Gcrypt */
g_string_append_printf(str, ", with Gcrypt %s", gcry_check_version(NULL)); 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 */ /* nghttp2 */
#if NGHTTP2_VERSION_AGE >= 1 #if NGHTTP2_VERSION_AGE >= 1
nghttp2_info *nghttp2_ptr = nghttp2_version(0); nghttp2_info *nghttp2_ptr = nghttp2_version(0);

View File

@ -11,14 +11,12 @@
#include "ftypes-int.h" #include "ftypes-int.h"
#include <wsutil/ws_assert.h> #include <wsutil/ws_assert.h>
#ifdef HAVE_PCRE2 #include <wsutil/ws_return.h>
#include <pcre2.h> #include <pcre2.h>
#endif
struct _fvalue_regex_t { struct _fvalue_regex_t {
void *code; pcre2_code *code;
char *pattern; char *pattern;
char *repr_debug;
}; };
/* Keep track of ftype_t's via their ftenum number */ /* 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); return a->ftype->cmp_matches(a, b);
} }
#ifdef HAVE_PCRE2
static pcre2_code * static pcre2_code *
_pcre2_compile(const char *patt, char **errmsg) _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; return rc < 0 ? FALSE : TRUE;
} }
#endif /* HAVE_PCRE2 */
fvalue_regex_t * fvalue_regex_t *
fvalue_regex_compile(const char *patt, char **errmsg) fvalue_regex_compile(const char *patt, char **errmsg)
{ {
void *code; ws_return_val_if_null(patt, NULL);
#ifdef HAVE_PCRE2 pcre2_code *code = _pcre2_compile(patt, errmsg);
code = _pcre2_compile(patt, errmsg);
#else
(void)patt;
code = NULL;
*errmsg = g_strdup("Wireshark was compiled without PCRE2");
#endif
if (code == NULL) if (code == NULL)
return NULL; return NULL;
fvalue_regex_t *re = g_new(fvalue_regex_t, 1); fvalue_regex_t *re = g_new(fvalue_regex_t, 1);
re->code = code; re->code = code;
re->pattern = g_strdup(patt); re->pattern = g_strdup(patt);
re->repr_debug = NULL;
return re; return re;
} }
gboolean gboolean
fvalue_regex_matches(const fvalue_regex_t *regex, const char *subj, gssize subj_size) fvalue_regex_matches(const fvalue_regex_t *regex, const char *subj, gssize subj_size)
{ {
#ifdef HAVE_PCRE2 ws_return_val_if_null(regex, FALSE);
ws_assert(regex != NULL); ws_return_val_if_null(subj, FALSE);
return _pcre2_matches(regex->code, subj, subj_size); return _pcre2_matches(regex->code, subj, subj_size);
#else
ws_assert(regex == NULL);
(void)subj;
(void)subj_size;
return FALSE;
#endif
} }
void void
fvalue_regex_free(fvalue_regex_t *regex) fvalue_regex_free(fvalue_regex_t *regex)
{ {
#ifdef HAVE_PCRE2
pcre2_code_free(regex->code); pcre2_code_free(regex->code);
#endif
g_free(regex->pattern); g_free(regex->pattern);
g_free(regex->repr_debug);
g_free(regex); 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 * const char *
fvalue_regex_pattern(const fvalue_regex_t *regex) fvalue_regex_pattern(const fvalue_regex_t *regex)
{ {

View File

@ -361,9 +361,6 @@ fvalue_regex_matches(const fvalue_regex_t *regex, const char *subj, gssize subj_
void void
fvalue_regex_free(fvalue_regex_t *regex); fvalue_regex_free(fvalue_regex_t *regex);
const char *
fvalue_regex_tostr(const fvalue_regex_t *regex, gboolean pretty);
const char * const char *
fvalue_regex_pattern(const fvalue_regex_t *regex); fvalue_regex_pattern(const fvalue_regex_t *regex);

View File

@ -101,9 +101,18 @@ if(NOT VCSVERSION_OVERRIDE)
add_dependencies(version_info vcs_version) add_dependencies(version_info vcs_version)
endif() 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 set_target_properties(ui version_info PROPERTIES
LINK_FLAGS "${WS_LINK_FLAGS}" LINK_FLAGS "${WS_LINK_FLAGS}"

View File

@ -25,6 +25,7 @@
#endif #endif
#include <glib.h> #include <glib.h>
#include <pcre2.h>
#ifdef HAVE_ZLIB #ifdef HAVE_ZLIB
#include <zlib.h> #include <zlib.h>
@ -175,6 +176,9 @@ get_compiled_version_info(void (*prepend_info)(GString *),
"GLib (version unknown)"); "GLib (version unknown)");
#endif #endif
/* PCRE2 */
g_string_append(str, ", with PCRE2");
g_string_append_printf(str, ", %s", get_zlib_compiled_version_info()); g_string_append_printf(str, ", %s", get_zlib_compiled_version_info());
/* Additional application-dependent information */ /* 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", g_string_append_printf(str, ", with GLib %u.%u.%u",
glib_major_version, glib_minor_version, glib_micro_version); 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 */ /* zlib */
#if defined(HAVE_ZLIB) && !defined(_WIN32) #if defined(HAVE_ZLIB) && !defined(_WIN32)
g_string_append_printf(str, ", with zlib %s", zlibVersion()); g_string_append_printf(str, ", with zlib %s", zlibVersion());