From 259f3c69bfffe5ccc999675f9edda5c99afc79a0 Mon Sep 17 00:00:00 2001 From: ellie timoney Date: Wed, 8 Nov 2023 14:23:10 +1100 Subject: [PATCH 1/5] various: add pcre2 support without removing pcre1 support Based on a patch from @yselkowitz in #4545 --- configure.ac | 21 +++++++++++++++++++++ docsrc/assets/cyrus-build-devpkg.rst | 2 +- docsrc/assets/cyrus-build-reqpkg.rst | 2 +- docsrc/imap/developer/compiling.rst | 3 ++- docsrc/imap/download/upgrade.rst | 2 +- imap/cyr_buildinfo.c | 5 +++++ lib/util.h | 21 ++++++++++++--------- ptclient/test3.c | 2 +- sieve/bc_eval.c | 4 +++- sieve/comparator.h | 21 ++++++++++++--------- sieve/sieve.y | 4 +++- 11 files changed, 62 insertions(+), 25 deletions(-) diff --git a/configure.ac b/configure.ac index cad8dd8f16..6b9f6a7a7c 100644 --- a/configure.ac +++ b/configure.ac @@ -678,6 +678,8 @@ AC_ARG_ENABLE(sieve, [AS_HELP_STRING([--disable-sieve], [disable Sieve support])],,[enable_sieve="yes";]) AC_ARG_ENABLE(pcre, [AS_HELP_STRING([--disable-pcre], [disable PCRE library])],[cyrus_cv_pcre_utf8="$enableval"]) +AC_ARG_ENABLE(pcre2, + [AS_HELP_STRING([--disable-pcre2], [disable PCRE2 library])],[cyrus_cv_pcre2_utf8="$enableval"]) if test "$enable_sieve" != "no"; then AC_DEFINE(USE_SIEVE,[],[Build in Sieve support?]) @@ -717,11 +719,29 @@ if test "$enable_pcre" != "no"; then fi fi +if test "$enable_pcre2" != "no"; then + AC_CHECK_HEADER(pcre2posix.h) + if test "$ac_cv_header_pcre2posix_h" = "yes"; then + AC_MSG_CHECKING(for utf8 enabled pcre2) + AC_CACHE_VAL(cyrus_cv_pcre2_utf8, AC_TRY_CPP([#include +#ifndef REG_UTF +#include +#endif],cyrus_cv_pcre2_utf8=yes,cyrus_cv_pcre2_utf8=no)) + AC_MSG_RESULT($cyrus_cv_pcre2_utf8) + else + cyrus_cv_pcre2_utf8="no" + fi +fi + LIB_REGEX= if test "$cyrus_cv_pcre_utf8" = "yes"; then LIB_REGEX="-lpcre -lpcreposix"; AC_DEFINE(ENABLE_REGEX, [], [Do we have a regex library?]) AC_DEFINE(HAVE_PCREPOSIX_H, [], [Do we have usable pcre library?]) +elif test "$cyrus_cv_pcre2_utf8" = "yes"; then + LIB_REGEX="-lpcre2-posix -lpcre2-8"; + AC_DEFINE(ENABLE_REGEX, [], [Do we have a regex library?]) + AC_DEFINE(HAVE_PCRE2POSIX_H, [], [Do we have usable pcre2 library?]) else AC_CHECK_HEADERS(rxposix.h) if test "$ac_cv_header_rxposix_h" = "yes"; then @@ -2569,6 +2589,7 @@ External dependencies: zlib: $with_zlib jansson: $with_jansson pcre: $cyrus_cv_pcre_utf8 + pcre2: $cyrus_cv_pcre2_utf8 clamav: $with_clamav ----------------------- caringo: $with_caringo diff --git a/docsrc/assets/cyrus-build-devpkg.rst b/docsrc/assets/cyrus-build-devpkg.rst index cf3eaef1b3..5c0156bb64 100644 --- a/docsrc/assets/cyrus-build-devpkg.rst +++ b/docsrc/assets/cyrus-build-devpkg.rst @@ -8,7 +8,7 @@ automated test facility. debhelper flex g++ git gperf groff heimdal-dev libbsd-resource-perl libclone-perl libconfig-inifiles-perl \ libcunit1-dev libdatetime-perl libbsd-dev libdigest-sha-perl libencode-imaputf7-perl \ libfile-chdir-perl libglib2.0-dev libical-dev libio-socket-inet6-perl \ libio-stringy-perl libldap2-dev libmysqlclient-dev \ - libnet-server-perl libnews-nntpclient-perl libpam0g-dev libpcre3-dev libsasl2-dev \ + libnet-server-perl libnews-nntpclient-perl libpam0g-dev libpcre2-dev libsasl2-dev \ libsqlite3-dev libssl-dev libtest-unit-perl libtool libunix-syslog-perl liburi-perl \ libxapian-dev libxml-generator-perl libxml-xpath-perl libxml2-dev libwrap0-dev libzephyr-dev lsb-base \ net-tools perl php-cli php-curl pkg-config po-debconf tcl-dev \ diff --git a/docsrc/assets/cyrus-build-reqpkg.rst b/docsrc/assets/cyrus-build-reqpkg.rst index a3a530cc39..1c8bb45951 100644 --- a/docsrc/assets/cyrus-build-reqpkg.rst +++ b/docsrc/assets/cyrus-build-reqpkg.rst @@ -2,6 +2,6 @@ sudo apt-get install git build-essential autoconf automake libtool \ pkg-config bison flex libssl-dev libjansson-dev libxml2-dev \ - libsqlite3-dev libical-dev libsasl2-dev libpcre3-dev uuid-dev \ + libsqlite3-dev libical-dev libsasl2-dev libpcre2-dev uuid-dev \ libicu-dev sudo apt-get -t jessie-backports install libxapian-dev diff --git a/docsrc/imap/developer/compiling.rst b/docsrc/imap/developer/compiling.rst index e05f3e43b1..2a351df5b1 100644 --- a/docsrc/imap/developer/compiling.rst +++ b/docsrc/imap/developer/compiling.rst @@ -194,7 +194,7 @@ Other to enable **ptloader** to interface with LDAP directly, for canonification of login usernames to mailbox names, and verification of login usernames, ACL subjects and group membership. Configure option: ``--with-ldap``." - `pcre`_, libpcre3-dev, pcre-devel, "yes", "PCRE 1 (8.x) - for utf-8/unicode + `pcre2`_, libpcre2-dev, pcre2-devel, "yes", "PCRE 2 (10.x) - for utf-8/unicode regular expression matching. Could be replaced by something else in the future. See `issues/1731`_ for more information." `perl(Term::ReadLine)`_,,, "no", "Perl library needed by **cyradm**." @@ -219,6 +219,7 @@ Other .. _nghttp2: https://nghttp2.org/ .. _openldap: http://www.openldap.org/ .. _pcre: http://www.pcre.org/ +.. _pcre2: http://www.pcre.org/ .. _perl(Term::ReadLine): https://metacpan.org/pod/Term::ReadLine .. _perl(ExtUtils::MakeMaker): http://search.cpan.org/dist/ExtUtils-MakeMaker/ .. _perl(Pod::POM::View::Restructured): https://metacpan.org/pod/Pod::POM::View::Restructured diff --git a/docsrc/imap/download/upgrade.rst b/docsrc/imap/download/upgrade.rst index 353a0114b8..09db9232b7 100644 --- a/docsrc/imap/download/upgrade.rst +++ b/docsrc/imap/download/upgrade.rst @@ -223,7 +223,7 @@ packages) for Debian is:: libcunit1-dev libdatetime-perl libdigest-sha-perl libencode-imaputf7-perl \ libfile-chdir-perl libglib2.0-dev libical-dev libio-socket-inet6-perl \ libio-stringy-perl libjansson-dev libldap2-dev libmysqlclient-dev \ - libnet-server-perl libnews-nntpclient-perl libpam0g-dev libpcre3-dev \ + libnet-server-perl libnews-nntpclient-perl libpam0g-dev libpcre2-dev \ libsasl2-dev libsqlite3-dev libssl-dev libtest-unit-perl libtool \ libunix-syslog-perl liburi-perl libxapian-dev libxml-generator-perl \ libxml-xpath-perl libxml2-dev libwrap0-dev libzephyr-dev lsb-base \ diff --git a/imap/cyr_buildinfo.c b/imap/cyr_buildinfo.c index 3d596c726a..a011101993 100644 --- a/imap/cyr_buildinfo.c +++ b/imap/cyr_buildinfo.c @@ -202,6 +202,11 @@ static json_t *buildinfo() #else json_object_set_new(dependency, "pcre", json_false()); #endif +#if defined(ENABLE_REGEX) && defined(HAVE_PCRE2POSIX_H) + json_object_set_new(dependency, "pcre2", json_true()); +#else + json_object_set_new(dependency, "pcre2", json_false()); +#endif #ifdef HAVE_CLAMAV json_object_set_new(dependency, "clamav", json_true()); #else diff --git a/lib/util.h b/lib/util.h index 7f7ab9f655..6cdd95a271 100644 --- a/lib/util.h +++ b/lib/util.h @@ -71,17 +71,20 @@ extern const char CYRUS_VERSION[]; #ifdef ENABLE_REGEX -# ifdef HAVE_PCREPOSIX_H +# if defined HAVE_PCREPOSIX_H # include # include -# else /* !HAVE_PCREPOSIX_H */ -# ifdef HAVE_RXPOSIX_H -# include -# else /* !HAVE_RXPOSIX_H */ -# include -# endif /* HAVE_RXPOSIX_H */ -# endif /* HAVE_PCREPOSIX_H */ -#endif /* ENABLE_REGEX */ +# elif defined HAVE_PCRE2POSIX_H +# ifndef PCRE2POSIX_H_INCLUDED +# include +# define PCRE2POSIX_H_INCLUDED +# endif +# elif defined HAVE_RXPOSIX_H +# include +# else +# include +# endif +#endif #ifdef HAVE_LIBUUID #include diff --git a/sieve/bc_eval.c b/sieve/bc_eval.c index 17241e166f..67d39355fa 100644 --- a/sieve/bc_eval.c +++ b/sieve/bc_eval.c @@ -321,9 +321,11 @@ static int regcomp_flags(int comparator, int requires) { int cflags = REG_EXTENDED; -#ifdef HAVE_PCREPOSIX_H /* support UTF8 comparisons */ +#if defined HAVE_PCREPOSIX_H cflags |= REG_UTF8; +#elif defined HAVE_PCRE2POSIX_H + cflags |= REG_UTF; #endif if (comparator == B_ASCIICASEMAP) { diff --git a/sieve/comparator.h b/sieve/comparator.h index b043bc296b..8c58bd1e73 100644 --- a/sieve/comparator.h +++ b/sieve/comparator.h @@ -47,17 +47,20 @@ #include #ifdef ENABLE_REGEX -# ifdef HAVE_PCREPOSIX_H +# if defined HAVE_PCREPOSIX_H # include # include -# else /* !HAVE_PCREPOSIX_H */ -# ifdef HAVE_RXPOSIX_H -# include -# else /* !HAVE_RXPOSIX_H */ -# include -# endif /* HAVE_RXPOSIX_H */ -# endif /* HAVE_PCREPOSIX_H */ -#endif /* ENABLE_REGEX */ +# elif defined HAVE_PCRE2POSIX_H +# ifndef PCRE2POSIX_H_INCLUDED +# include +# define PCRE2POSIX_H_INCLUDED +# endif +# elif defined HAVE_RXPOSIX_H +# include +# else +# include +# endif +#endif #include "sieve_interface.h" #include "strarray.h" diff --git a/sieve/sieve.y b/sieve/sieve.y index 71aa503bd3..17adb65112 100644 --- a/sieve/sieve.y +++ b/sieve/sieve.y @@ -2143,9 +2143,11 @@ static int verify_regexlist(sieve_script_t *sscript, regex_t reg; int cflags = REG_EXTENDED | REG_NOSUB; -#ifdef HAVE_PCREPOSIX_H /* support UTF8 comparisons */ +#if defined HAVE_PCREPOSIX_H cflags |= REG_UTF8; +#elif defined HAVE_PCRE2POSIX_H + cflags |= REG_UTF; #endif if (collation == B_ASCIICASEMAP) { From 7c7e1957d9a8074aa3dd7fe113cf551eadcb494f Mon Sep 17 00:00:00 2001 From: ellie timoney Date: Mon, 13 Nov 2023 11:10:28 +1100 Subject: [PATCH 2/5] configure.ac: tidy up sieve/pcre checks --- configure.ac | 101 ++++++++++++++++++++++++++------------------------- 1 file changed, 51 insertions(+), 50 deletions(-) diff --git a/configure.ac b/configure.ac index 6b9f6a7a7c..975925bebe 100644 --- a/configure.ac +++ b/configure.ac @@ -675,82 +675,83 @@ AM_CONDITIONAL([SQUATTER], [test "${enable_squat}" != "no" -o "${enable_xapian}" != "no" ]) AC_ARG_ENABLE(sieve, - [AS_HELP_STRING([--disable-sieve], [disable Sieve support])],,[enable_sieve="yes";]) -AC_ARG_ENABLE(pcre, - [AS_HELP_STRING([--disable-pcre], [disable PCRE library])],[cyrus_cv_pcre_utf8="$enableval"]) -AC_ARG_ENABLE(pcre2, - [AS_HELP_STRING([--disable-pcre2], [disable PCRE2 library])],[cyrus_cv_pcre2_utf8="$enableval"]) + [AS_HELP_STRING([--disable-sieve], [disable Sieve support])],,[enable_sieve="yes";]) if test "$enable_sieve" != "no"; then - AC_DEFINE(USE_SIEVE,[],[Build in Sieve support?]) + AC_DEFINE(USE_SIEVE,[],[Build in Sieve support?]) - if test "x$HAVE_SQLITE" != x1; then - AC_MSG_ERROR([Need sqlite3 for sieve]) - else - use_sqlite="yes" - fi + if test "x$HAVE_SQLITE" != x1; then + AC_MSG_ERROR([Need sqlite3 for sieve]) + else + use_sqlite="yes" + fi - dnl Sieve configure stuff - AC_PROG_YACC - AM_PROG_LEX + dnl Sieve configure stuff + AC_PROG_YACC + AM_PROG_LEX - if test -z "$ac_cv_prog_YACC"; then - AC_MSG_ERROR([Sieve requires bison/byacc/yacc, but none is installed]) - fi + if test -z "$ac_cv_prog_YACC"; then + AC_MSG_ERROR([Sieve requires bison/byacc/yacc, but none is installed]) + fi - if test -z "$ac_cv_prog_LEX"; then - AC_MSG_ERROR([Sieve requires flex/lex, but none is installed]) - fi + if test -z "$ac_cv_prog_LEX"; then + AC_MSG_ERROR([Sieve requires flex/lex, but none is installed]) + fi fi AM_CONDITIONAL([SIEVE], [test "${enable_sieve}" != "no"]) +AC_ARG_ENABLE(pcre, + [AS_HELP_STRING([--disable-pcre], [disable PCRE library])],[cyrus_cv_pcre_utf8="$enableval"]) +AC_ARG_ENABLE(pcre2, + [AS_HELP_STRING([--disable-pcre2], [disable PCRE2 library])],[cyrus_cv_pcre2_utf8="$enableval"]) + if test "$enable_pcre" != "no"; then - AC_CHECK_HEADER(pcreposix.h) - if test "$ac_cv_header_pcreposix_h" = "yes"; then - AC_MSG_CHECKING(for utf8 enabled pcre) - AC_CACHE_VAL(cyrus_cv_pcre_utf8, AC_TRY_CPP([#include + AC_CHECK_HEADER(pcreposix.h) + if test "$ac_cv_header_pcreposix_h" = "yes"; then + AC_MSG_CHECKING(for utf8 enabled pcre) + AC_CACHE_VAL(cyrus_cv_pcre_utf8, AC_TRY_CPP([#include #ifndef REG_UTF8 #include #endif],cyrus_cv_pcre_utf8=yes,cyrus_cv_pcre_utf8=no)) - AC_MSG_RESULT($cyrus_cv_pcre_utf8) - else - cyrus_cv_pcre_utf8="no" - fi + AC_MSG_RESULT($cyrus_cv_pcre_utf8) + else + cyrus_cv_pcre_utf8="no" + fi fi if test "$enable_pcre2" != "no"; then - AC_CHECK_HEADER(pcre2posix.h) - if test "$ac_cv_header_pcre2posix_h" = "yes"; then - AC_MSG_CHECKING(for utf8 enabled pcre2) - AC_CACHE_VAL(cyrus_cv_pcre2_utf8, AC_TRY_CPP([#include + AC_CHECK_HEADER(pcre2posix.h) + if test "$ac_cv_header_pcre2posix_h" = "yes"; then + AC_MSG_CHECKING(for utf8 enabled pcre2) + AC_CACHE_VAL(cyrus_cv_pcre2_utf8, AC_TRY_CPP([#include #ifndef REG_UTF #include #endif],cyrus_cv_pcre2_utf8=yes,cyrus_cv_pcre2_utf8=no)) - AC_MSG_RESULT($cyrus_cv_pcre2_utf8) - else - cyrus_cv_pcre2_utf8="no" - fi + AC_MSG_RESULT($cyrus_cv_pcre2_utf8) + else + cyrus_cv_pcre2_utf8="no" + fi fi LIB_REGEX= if test "$cyrus_cv_pcre_utf8" = "yes"; then - LIB_REGEX="-lpcre -lpcreposix"; - AC_DEFINE(ENABLE_REGEX, [], [Do we have a regex library?]) - AC_DEFINE(HAVE_PCREPOSIX_H, [], [Do we have usable pcre library?]) + LIB_REGEX="-lpcre -lpcreposix"; + AC_DEFINE(ENABLE_REGEX, [], [Do we have a regex library?]) + AC_DEFINE(HAVE_PCREPOSIX_H, [], [Do we have usable pcre library?]) elif test "$cyrus_cv_pcre2_utf8" = "yes"; then - LIB_REGEX="-lpcre2-posix -lpcre2-8"; - AC_DEFINE(ENABLE_REGEX, [], [Do we have a regex library?]) - AC_DEFINE(HAVE_PCRE2POSIX_H, [], [Do we have usable pcre2 library?]) + LIB_REGEX="-lpcre2-posix -lpcre2-8"; + AC_DEFINE(ENABLE_REGEX, [], [Do we have a regex library?]) + AC_DEFINE(HAVE_PCRE2POSIX_H, [], [Do we have usable pcre2 library?]) else - AC_CHECK_HEADERS(rxposix.h) - if test "$ac_cv_header_rxposix_h" = "yes"; then - LIB_REGEX="-lrx" - AC_DEFINE(ENABLE_REGEX, [], [Do we have a regex library?]) - else - AC_SEARCH_LIBS(regcomp, regex, - AC_DEFINE(ENABLE_REGEX, [], [Do we have a regex library?]), []) - fi + AC_CHECK_HEADERS(rxposix.h) + if test "$ac_cv_header_rxposix_h" = "yes"; then + LIB_REGEX="-lrx" + AC_DEFINE(ENABLE_REGEX, [], [Do we have a regex library?]) + else + AC_SEARCH_LIBS(regcomp, regex, + AC_DEFINE(ENABLE_REGEX, [], [Do we have a regex library?]), []) + fi fi AC_SUBST(LIB_REGEX) LIBS="$LIBS $LIB_REGEX" From b9002dba94eaa8a688df4f3c280db31a4eb77f69 Mon Sep 17 00:00:00 2001 From: ellie timoney Date: Mon, 13 Nov 2023 11:32:13 +1100 Subject: [PATCH 3/5] configure.ac: use pkg-config to find pcre/pcre2 Fixes #4711 --- configure.ac | 73 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 24 deletions(-) diff --git a/configure.ac b/configure.ac index 975925bebe..7fed07e129 100644 --- a/configure.ac +++ b/configure.ac @@ -707,42 +707,65 @@ AC_ARG_ENABLE(pcre2, [AS_HELP_STRING([--disable-pcre2], [disable PCRE2 library])],[cyrus_cv_pcre2_utf8="$enableval"]) if test "$enable_pcre" != "no"; then - AC_CHECK_HEADER(pcreposix.h) - if test "$ac_cv_header_pcreposix_h" = "yes"; then - AC_MSG_CHECKING(for utf8 enabled pcre) - AC_CACHE_VAL(cyrus_cv_pcre_utf8, AC_TRY_CPP([#include -#ifndef REG_UTF8 -#include -#endif],cyrus_cv_pcre_utf8=yes,cyrus_cv_pcre_utf8=no)) - AC_MSG_RESULT($cyrus_cv_pcre_utf8) - else - cyrus_cv_pcre_utf8="no" - fi + PKG_CHECK_MODULES([PCRE], + [libpcreposix libpcre], + [ AC_MSG_CHECKING(for utf8 enabled pcre) + saved_CFLAGS="$CFLAGS" + saved_LIBS="$LIBS" + CFLAGS="$CFLAGS PCRE_CFLAGS" + LIBS="$LIBS PCRE_LIBS" + AC_CACHE_VAL(cyrus_cv_pcre_utf8, + AC_TRY_CPP([ #include + #ifndef REG_UTF8 + #include + #endif + ], + [cyrus_cv_pcre_utf8=yes], + [cyrus_cv_pcre_utf8=no])) + AC_MSG_RESULT($cyrus_cv_pcre_utf8) + CFLAGS="$saved_CFLAGS" + LIBS="$saved_LIBS" + ], + [cyrus_cv_pcre_utf8="no"]) fi if test "$enable_pcre2" != "no"; then - AC_CHECK_HEADER(pcre2posix.h) - if test "$ac_cv_header_pcre2posix_h" = "yes"; then - AC_MSG_CHECKING(for utf8 enabled pcre2) - AC_CACHE_VAL(cyrus_cv_pcre2_utf8, AC_TRY_CPP([#include -#ifndef REG_UTF -#include -#endif],cyrus_cv_pcre2_utf8=yes,cyrus_cv_pcre2_utf8=no)) - AC_MSG_RESULT($cyrus_cv_pcre2_utf8) - else - cyrus_cv_pcre2_utf8="no" - fi + PKG_CHECK_MODULES([PCRE2], + [libpcre2-posix libpcre2-8], + [ AC_MSG_CHECKING(for utf8 enabled pcre2) + saved_CFLAGS="$CFLAGS" + saved_LIBS="$LIBS" + CFLAGS="$CFLAGS PCRE2_CFLAGS" + LIBS="$LIBS PCRE2_LIBS" + AC_CACHE_VAL(cyrus_cv_pcre2_utf8, + AC_TRY_CPP([ #include + #ifndef REG_UTF + #include + #endif + ], + [cyrus_cv_pcre2_utf8=yes], + [cyrus_cv_pcre2_utf8=no])) + AC_MSG_RESULT($cyrus_cv_pcre2_utf8) + CFLAGS="$saved_CFLAGS" + LIBS="$saved_LIBS" + ], + [cyrus_cv_pcre2_utf8="no"]) fi LIB_REGEX= +CFLAGS_REGEX= if test "$cyrus_cv_pcre_utf8" = "yes"; then - LIB_REGEX="-lpcre -lpcreposix"; + CFLAGS_REGEX="$PCRE_CFLAGS" + LIB_REGEX="$PCRE_LIBS"; AC_DEFINE(ENABLE_REGEX, [], [Do we have a regex library?]) AC_DEFINE(HAVE_PCREPOSIX_H, [], [Do we have usable pcre library?]) + cyrus_cv_pcre2_utf8="no" elif test "$cyrus_cv_pcre2_utf8" = "yes"; then - LIB_REGEX="-lpcre2-posix -lpcre2-8"; + CFLAGS_REGEX="$PCRE2_CFLAGS" + LIB_REGEX="$PCRE2_LIBS" AC_DEFINE(ENABLE_REGEX, [], [Do we have a regex library?]) AC_DEFINE(HAVE_PCRE2POSIX_H, [], [Do we have usable pcre2 library?]) + cyrus_cv_pcre_utf8="no" else AC_CHECK_HEADERS(rxposix.h) if test "$ac_cv_header_rxposix_h" = "yes"; then @@ -754,7 +777,9 @@ else fi fi AC_SUBST(LIB_REGEX) +AC_SUBST(CFLAGS_REGEX) LIBS="$LIBS $LIB_REGEX" +CFLAGS="$CFLAGS $CFLAGS_REGEX" dnl dnl see if we're compiling with SRS From 3ff27055f73097123b7c1c8e3d83adc1f1c1f026 Mon Sep 17 00:00:00 2001 From: ellie timoney Date: Mon, 13 Nov 2023 13:38:25 +1100 Subject: [PATCH 4/5] configure.ac: prefer pcre2 if both available --- configure.ac | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index 7fed07e129..186b0f1872 100644 --- a/configure.ac +++ b/configure.ac @@ -754,18 +754,18 @@ fi LIB_REGEX= CFLAGS_REGEX= -if test "$cyrus_cv_pcre_utf8" = "yes"; then - CFLAGS_REGEX="$PCRE_CFLAGS" - LIB_REGEX="$PCRE_LIBS"; - AC_DEFINE(ENABLE_REGEX, [], [Do we have a regex library?]) - AC_DEFINE(HAVE_PCREPOSIX_H, [], [Do we have usable pcre library?]) - cyrus_cv_pcre2_utf8="no" -elif test "$cyrus_cv_pcre2_utf8" = "yes"; then +if test "$cyrus_cv_pcre2_utf8" = "yes"; then CFLAGS_REGEX="$PCRE2_CFLAGS" LIB_REGEX="$PCRE2_LIBS" AC_DEFINE(ENABLE_REGEX, [], [Do we have a regex library?]) AC_DEFINE(HAVE_PCRE2POSIX_H, [], [Do we have usable pcre2 library?]) cyrus_cv_pcre_utf8="no" +elif test "$cyrus_cv_pcre_utf8" = "yes"; then + CFLAGS_REGEX="$PCRE_CFLAGS" + LIB_REGEX="$PCRE_LIBS"; + AC_DEFINE(ENABLE_REGEX, [], [Do we have a regex library?]) + AC_DEFINE(HAVE_PCREPOSIX_H, [], [Do we have usable pcre library?]) + cyrus_cv_pcre2_utf8="no" else AC_CHECK_HEADERS(rxposix.h) if test "$ac_cv_header_rxposix_h" = "yes"; then From 1dc08fef4805f74a0b4f51dd090337d8c75f9e10 Mon Sep 17 00:00:00 2001 From: ellie timoney Date: Mon, 13 Nov 2023 14:15:33 +1100 Subject: [PATCH 5/5] add changes file --- changes/next/pcre2-support | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 changes/next/pcre2-support diff --git a/changes/next/pcre2-support b/changes/next/pcre2-support new file mode 100644 index 0000000000..87ac924f94 --- /dev/null +++ b/changes/next/pcre2-support @@ -0,0 +1,30 @@ +Description: + +Adds pcre2 support. Prefers pcre2 over pcre if both are available. + + +Config changes: + +None + + +Upgrade instructions: + +Cyrus will prefer pcre2 over pcre if both are installed. If you have both +installed and wish to use pcre rather than pcre2, run configure with +--disable-pcre2. + +If you haven't specifically installed libpcre2-dev (or whatever your system's +equivalent is), you might still have parts of pcre2 installed due to other +packages on your system depending on it. This can confuse configure into +thinking you have a usable pcre2 when you don't. Either properly install +libpcre2-dev so Cyrus can use it, or configure Cyrus with --disable-pcre2 +so that it ignores the partial installation. + +Please note that on Debian-based systems, pcre (the old one, no longer +maintained) is called "pcre3". Yes, this is confusing. + + +GitHub issue: + +#3861 #4711 From 19f286ad8f2eda1cccb688edb7369050d92bb6c6 Mon Sep 17 00:00:00 2001 From: ellie timoney Date: Wed, 22 Nov 2023 16:28:14 +1100 Subject: [PATCH 1/4] Sieve: add bad regex case to badscript tests --- cassandane/Cassandane/Cyrus/Sieve.pm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cassandane/Cassandane/Cyrus/Sieve.pm b/cassandane/Cassandane/Cyrus/Sieve.pm index 2cd463f37f..0f0a3e66a6 100644 --- a/cassandane/Cassandane/Cyrus/Sieve.pm +++ b/cassandane/Cassandane/Cyrus/Sieve.pm @@ -488,6 +488,16 @@ sub badscript_common "require [\"fileinto\",\"copy\"];\nfileinto :copy \"foo\";\n"); $self->assert_str_equals('success', $res); + my $badregex1 = << 'EOF'; +require ["regex"]; +if header :regex "Subject" "Message (x)?(.*" { + stop; +} +EOF + ($res, $errs) = $self->compile_sieve_script('badregex1', $badregex1); + $self->assert_str_equals('failure', $res); + $self->assert_matches(qr/unbalanced/, $errs); + # TODO: test UTF-8 verification of the string parameter } From 0395da350fdca0b8af57f01decc26d9ccc5375eb Mon Sep 17 00:00:00 2001 From: ellie timoney Date: Wed, 22 Nov 2023 16:29:12 +1100 Subject: [PATCH 2/4] sieve/sieve.y: fix pcre2 crash when regex_t uninitialised Fixes crash when trying to regfree() after regcomp() failure Seems like this usage was fine with the old pcreposix, but is a problem with pcre2posix. --- sieve/sieve.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sieve/sieve.y b/sieve/sieve.y index 17adb65112..908f2a4ed0 100644 --- a/sieve/sieve.y +++ b/sieve/sieve.y @@ -2140,7 +2140,6 @@ static int verify_regexlist(sieve_script_t *sscript, const strarray_t *sa, int collation) { int i, ret = 0; - regex_t reg; int cflags = REG_EXTENDED | REG_NOSUB; /* support UTF8 comparisons */ @@ -2156,6 +2155,7 @@ static int verify_regexlist(sieve_script_t *sscript, for (i = 0 ; !ret && i < strarray_size(sa) ; i++) { const char *s = strarray_nth(sa, i); + regex_t reg = {0}; /* Don't try to validate a regex that includes variables */ if (supported(SIEVE_CAPA_VARIABLES) && strstr(s, "${")) continue; From eae2966b2198b4446a5f311cb6b25070dffa4335 Mon Sep 17 00:00:00 2001 From: ellie timoney Date: Wed, 22 Nov 2023 16:50:52 +1100 Subject: [PATCH 3/4] buf.testc: regcomp failure is fatal --- cunit/buf.testc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cunit/buf.testc b/cunit/buf.testc index 19f52e8cb2..c88a54e8b0 100644 --- a/cunit/buf.testc +++ b/cunit/buf.testc @@ -646,7 +646,7 @@ static void test_replace_all(void) CU_ASSERT_STRING_EQUAL(b.s, _in); \ \ r = regcomp(&re, _reg, REG_EXTENDED); \ - CU_ASSERT_EQUAL(r, 0); + CU_ASSERT_EQUAL_FATAL(r, 0); #define TESTCASE_MIDDLE \ n = buf_replace_one_re(&b, &re, _rep); #define TESTCASE_END \ From ba43ab2462adca1a6f2dbfc54d967f02bd1dcb33 Mon Sep 17 00:00:00 2001 From: ellie timoney Date: Wed, 22 Nov 2023 16:51:37 +1100 Subject: [PATCH 4/4] glob: assert that regcomp succeeded instead of assuming it succeeded --- lib/glob.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/glob.c b/lib/glob.c index 06d5cb282b..89c45f0eae 100644 --- a/lib/glob.c +++ b/lib/glob.c @@ -46,6 +46,7 @@ #include #include #include +#include #include "util.h" #include "glob.h" #include "xmalloc.h" @@ -58,6 +59,7 @@ EXPORTED glob *glob_init(const char *str, char sep) { struct buf buf = BUF_INITIALIZER; + int r; buf_appendcstr(&buf, "(^"); while (*str) { @@ -109,7 +111,9 @@ EXPORTED glob *glob_init(const char *str, char sep) buf_appendcstr(&buf, "]|$)"); glob *g = xmalloc(sizeof(glob)); - regcomp(&g->regex, buf_cstring(&buf), REG_EXTENDED); + r = regcomp(&g->regex, buf_cstring(&buf), REG_EXTENDED); + /* XXX handle regex compilation failure properly! */ + assert(r == 0); buf_free(&buf); return g;