From f513ac431f1de4f34d9ed287430846ee5b0ee408 Mon Sep 17 00:00:00 2001 From: eaglegai Date: Wed, 1 Jun 2022 16:08:56 +0800 Subject: [PATCH] switch from pcre to pcre2 --- backport-001-Convert-to-pcre2.patch | 383 ++++++++++++++++++++++++++++ backport-002-Convert-to-PCRE2.patch | 180 +++++++++++++ maildrop.spec | 11 +- 3 files changed, 572 insertions(+), 2 deletions(-) create mode 100644 backport-001-Convert-to-pcre2.patch create mode 100644 backport-002-Convert-to-PCRE2.patch diff --git a/backport-001-Convert-to-pcre2.patch b/backport-001-Convert-to-pcre2.patch new file mode 100644 index 0000000..dd7b89f --- /dev/null +++ b/backport-001-Convert-to-pcre2.patch @@ -0,0 +1,383 @@ +From 00664cc3ece7c29843771561fe2890b635f2b74e Mon Sep 17 00:00:00 2001 +From: Sam Varshavchik +Date: Fri, 26 Nov 2021 13:06:23 -0500 +Subject: [PATCH] Convert to pcre2. + +--- + maildrop/Makefile.am | 6 +- + maildrop/configure.ac | 9 ++- + maildrop/search.C | 139 +++++++++++++++++++++--------------------- + maildrop/search.h | 24 ++++---- + configure.ac | 12 +++--- + 5 files changed, 92 insertions(+), 98 deletions(-) + +diff --git a/maildrop/Makefile.am b/maildrop/Makefile.am +index 5f94c37..154cebe 100644 +--- a/libs/maildrop/Makefile.am ++++ b/libs/maildrop/Makefile.am +@@ -3,7 +3,7 @@ + # distribution information. + + +-AM_CPPFLAGS=@AUTHINCLUDE@ ++AM_CPPFLAGS := @AUTHINCLUDE@ `pcre2-config --cflags` + + DISTCLEANFILES=uidgid testmailbot.* + CLEANFILES=maildrop.html maildrop.1 maildropfilter.7 maildropfilter.html +@@ -46,8 +46,8 @@ maildrop_SOURCES=deliver.C deliverdotlock.C deliverdotlock.h \ + + maildrop_DEPENDENCIES = libmdcommon.la + +-maildrop_LDADD = libmdcommon.la @AUTHLDADD@ -lpcre +-maildrop_LDFLAGS= ++maildrop_LDADD = libmdcommon.la @AUTHLDADD@ ++maildrop_LDFLAGS= `pcre2-config --libs8` + + reformail_SOURCES=reformail.C + reformail_LDADD = libmdcommon.la +diff --git a/maildrop/configure.ac b/maildrop/configure.ac +index fca57fe..63acdfb 100644 +--- a/libs/maildrop/configure.ac ++++ b/libs/maildrop/configure.ac +@@ -159,7 +159,7 @@ AC_HEADER_STDC + AC_HEADER_SYS_WAIT + AC_HEADER_TIME + AC_HEADER_DIRENT +-AC_CHECK_HEADERS(fcntl.h memory.h sys/file.h sys/time.h sys/stat.h unistd.h strings.h locale.h pcre.h pcre/pcre.h) ++AC_CHECK_HEADERS(fcntl.h memory.h sys/file.h sys/time.h sys/stat.h unistd.h strings.h locale.h) + + dnl Checks for typedefs, structures, and compiler characteristics. + AC_TYPE_MODE_T +@@ -301,6 +301,13 @@ else + AC_CHECK_PROG(QMAIL,qmail-inject,qmail-inject,) + fi + ++AC_CHECK_PROG(PCRE2, pcre2-config, yes, no) ++ ++if test "$PCRE2" = "no" ++then ++ AC_MSG_ERROR([pcre2 library not found]) ++fi ++ + dnl Try to find sendmail. + + test "x$prefix" = xNONE && prefix=$ac_default_prefix +diff --git a/maildrop/search.C b/maildrop/search.C +index 9add6ee..32d4ce6 100644 +--- a/libs/maildrop/search.C ++++ b/libs/maildrop/search.C +@@ -12,22 +12,17 @@ + + void Search::cleanup() + { +- if (pcre_regexp_extra) ++ if (match_data) + { +- pcre_free(pcre_regexp_extra); +- pcre_regexp_extra=NULL; ++ pcre2_match_data_free(match_data); ++ match_data=NULL; + } ++ + if (pcre_regexp) + { +- pcre_free(pcre_regexp); ++ pcre2_code_free(pcre_regexp); + pcre_regexp=NULL; + } +- +- if (pcre_vectors) +- { +- free(pcre_vectors); +- pcre_vectors=NULL; +- } + } + + int Search::init(const char *expr, const char *opts) +@@ -51,69 +46,55 @@ int Search::init(const char *expr, const char *opts) + if (strchr(opts, 'w')) match_body=1; + } + +- const char *errptr; ++ int errcode; + + cleanup(); + +- int errindex; ++ PCRE2_SIZE errindex; + +- pcre_regexp=pcre_compile(expr, +- PCRE_UTF8 | (strchr(opts, 'D') ? 0:PCRE_CASELESS), +- &errptr, +- &errindex, 0); ++ pcre_regexp=pcre2_compile((PCRE2_SPTR8)expr, ++ PCRE2_ZERO_TERMINATED, ++ PCRE2_UTF | (strchr(opts, 'D') ? 0:PCRE2_CASELESS), ++ &errcode, ++ &errindex, ++ NULL); + + if (!pcre_regexp) + { + Buffer b; + ++ PCRE2_UCHAR buffer[256]; ++ pcre2_get_error_message(errcode, buffer, sizeof(buffer)); ++ + b="Invalid regular expression, offset "; + b.append((unsigned long)errindex); + b += " of: "; + b += expr; + b += ": "; +- b += errptr; ++ b += (char *)buffer; + b += "\n"; + b += '\0'; + merr.write(b); + return -1; + } + +- pcre_regexp_extra=pcre_study(pcre_regexp, 0, &errptr); ++ match_data= pcre2_match_data_create_from_pattern( ++ pcre_regexp, NULL ++ ); + +- if (errptr) ++ if (!match_data) + { + Buffer b; + +- b="Error parsing regular expression: "; ++ b="Failed to create match data for: "; + b += expr; +- b += ": "; +- b += errptr; + b += "\n"; + b += '\0'; + merr.write(b); ++ cleanup(); + return -1; + } +- + search_expr=expr; +- int cnt=0; +- +- pcre_fullinfo(pcre_regexp, pcre_regexp_extra, +- PCRE_INFO_CAPTURECOUNT, &cnt); +- +- pcre_vector_count=(cnt+1)*3; +- +- pcre_vectors=(int *)malloc(pcre_vector_count*sizeof(int)); +- +- if (!pcre_vectors) +- { +- Buffer b; +- +- b=strerror(errno); +- b += "\n"; +- b += '\0'; +- merr.write(b); +- return -1; +- } + + while (*opts) + { +@@ -166,30 +147,40 @@ int Search::find(const char *str, const char *expr, const char *opts, + + int startoffset=0; + const char *orig_str=str; +- int match_count=0; + + for (;;) + { +- match_count=pcre_exec(pcre_regexp, pcre_regexp_extra, +- orig_str, strlen(orig_str), +- startoffset, +- 0, +- pcre_vectors, +- pcre_vector_count); +- if (match_count <= 0) ++ int rc=pcre2_match(pcre_regexp, ++ (PCRE2_SPTR8)orig_str, ++ strlen(orig_str), ++ startoffset, ++ 0, ++ match_data, ++ NULL); ++ ++ if (rc < 0 ) + break; +- startoffset=pcre_vectors[1]; ++ ++ ++ PCRE2_SIZE *ovector=pcre2_get_ovector_pointer(match_data); ++ uint32_t ovector_count=pcre2_get_ovector_count(match_data); + + score += weight1; + weight1 *= weight2; + + if (!scoring_match || foreachp) + { +- init_match_vars(orig_str, match_count, +- pcre_vectors, foreachp); ++ init_match_vars(orig_str, ovector, ovector_count, ++ foreachp); + if (!foreachp) + break; + } ++ ++ if (!ovector || ovector_count <= 0) ++ break; ++ ++ startoffset=ovector[1]; ++ + } + return (0); + } +@@ -263,27 +254,32 @@ int Search::search_cb(const char *ptr, size_t cnt) + } + + const char *orig_str=current_line; +- int match_count; +- +- match_count=pcre_exec(pcre_regexp, +- pcre_regexp_extra, +- orig_str, +- strlen(orig_str), +- 0, +- 0, +- pcre_vectors, +- pcre_vector_count); +- +- if (match_count > 0) ++ ++ int rc=pcre2_match(pcre_regexp, ++ (PCRE2_SPTR8)orig_str, ++ strlen(orig_str), ++ 0, ++ 0, ++ match_data, ++ NULL); ++ ++ if (rc >= 0) + { + score += weight1; + weight1 *= weight2; + + if (!scoring_match || foreachp_arg) + { ++ PCRE2_SIZE *ovector= ++ pcre2_get_ovector_pointer( ++ match_data); ++ uint32_t ovector_count= ++ pcre2_get_ovector_count( ++ match_data); ++ + init_match_vars(orig_str, +- match_count, +- pcre_vectors, ++ ovector, ++ ovector_count, + foreachp_arg); + if (!foreachp_arg) + // Stop searching now +@@ -311,11 +307,16 @@ int Search::search_cb(const char *ptr, size_t cnt) + return (0); + } + +-void Search::init_match_vars(const char *str, int nranges, int *offsets, ++void Search::init_match_vars(const char *str, ++ PCRE2_SIZE *offsets, ++ uint32_t nranges, + Buffer *foreachp) + { + Buffer varname; +- int cnt; ++ uint32_t cnt; ++ ++ if (!offsets) ++ return; + + for (cnt=0; cnt +-#else +-#include +-#endif ++#define PCRE2_CODE_UNIT_WIDTH 8 ++ ++#include + + //////////////////////////////////////////////////////////////////////////// + // +@@ -42,10 +40,8 @@ class Message; + + class Search { + +- pcre *pcre_regexp; +- pcre_extra *pcre_regexp_extra; +- int *pcre_vectors; +- size_t pcre_vector_count; ++ pcre2_code *pcre_regexp; ++ pcre2_match_data *match_data; + + Buffer current_line; + Buffer next_line; +@@ -62,8 +58,8 @@ public: + double score; // For weighted scoring. Without scoring, this is + // either 0, or 1. + +- Search() : pcre_regexp(NULL), pcre_regexp_extra(NULL), +- pcre_vectors(NULL) {} ++ Search() : pcre_regexp(NULL), ++ match_data(NULL) {} + ~Search() { cleanup(); } + int find(Message &, MessageInfo &, const char *, const char *, + Buffer *); +@@ -71,8 +67,10 @@ public: + private: + int findinline(Message &, const char *, Buffer *); + int findinsection(Message &, const char *, Buffer *); +- void init_match_vars(const char *, int, int *, Buffer *); +- ++ void init_match_vars(const char *, ++ PCRE2_SIZE *, ++ uint32_t, ++ Buffer *); + Buffer search_expr; + Buffer *foreachp_arg; + static int search_cb(const char *ptr, size_t cnt, void *arg); +diff --git a/configure.ac b/configure.ac +index d118fec..e311082 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -17,18 +17,6 @@ AC_PROG_LN_S + AC_PROG_MAKE_SET + AM_PROG_LIBTOOL + +-AC_CHECK_HEADER([pcre.h], +- [ : ], +- [ +- +- AC_CHECK_HEADER([pcre/pcre.h], +- [ : ], +- [ +- AC_MSG_ERROR(pcre.h not found - install PCRE from www.pcre.org) +- ]) +- ] +-) +- + test "x$prefix" = xNONE && prefix=$ac_default_prefix + test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' + +-- +2.27.0 diff --git a/backport-002-Convert-to-PCRE2.patch b/backport-002-Convert-to-PCRE2.patch new file mode 100644 index 0000000..0c57c6c --- /dev/null +++ b/backport-002-Convert-to-PCRE2.patch @@ -0,0 +1,180 @@ +From ba64de5232d3b0124e540124fcded55f8c4d42ab Mon Sep 17 00:00:00 2001 +From: Sam Varshavchik +Date: Sun, 28 Nov 2021 10:17:28 -0500 +Subject: [PATCH] Convert to PCRE2. + +--- + maildir/Makefile.am | 23 +++++++++++++---------- + maildir/configure.ac | 17 ++++++++++------- + maildir/maildirfilter.c | 35 ++++++++++++++++------------------- + maildrop/configure.ac | 2 +- + 4 files changed, 41 insertions(+), 37 deletions(-) + +diff --git a/maildir/Makefile.am b/maildir/Makefile.am +index 54c0602..fa00669 100644 +--- a/libs/maildir/Makefile.am ++++ b/libs/maildir/Makefile.am +@@ -3,6 +3,7 @@ + # distribution information. + + AM_CXXFLAGS=@COURIER_UNICODE_CXXFLAGS@ ++AM_CFLAGS=@PCRE_CFLAGS@ + + noinst_LTLIBRARIES=libmaildir.la + +@@ -15,17 +16,19 @@ DOCS= deliverquota.html.in deliverquota.8.in \ + maildirwatch.html maildirwatch.1 \ + maildirkw.html maildirkw.1 + +-if HAVE_SGML +-BUILT_SOURCES=maildirsharedrc.h maildirfilterconfig.h quotawarnmsg.h \ +- mailbot.h autoresponsequota.h $(noinst_DATA) $(DOCS) +-else + BUILT_SOURCES=maildirsharedrc.h maildirfilterconfig.h quotawarnmsg.h \ +- mailbot.h autoresponsequota.h $(noinst_DATA) ++ mailbot.h autoresponsequota.h $(noinst_DATA) libmaildir.deps ++ ++if HAVE_SGML ++BUILT_SOURCES += $(DOCS) + endif + + noinst_DATA=deliverquota.html maildirmake.html deliverquota.8 maildirmake.1 \ + maildiracl.html maildiracl.1 + ++libmaildir.deps: config.status ++ echo "$(PCRE_LDFLAGS)" >libmaildir.deps ++ + libmaildir_la_SOURCES=autoresponse.c autoresponse.h \ + maildiraclt.c maildiraclt.h \ + maildircache.c maildircache.h \ +@@ -64,13 +67,13 @@ maildirmake_DEPENDENCIES=libmaildir.la \ + ../rfc822/librfc822.la + maildirmake_LDADD=libmaildir.la \ + ../numlib/libnumlib.la \ +- ../rfc822/librfc822.la -lcourier-unicode @LIBPCRE@ +-maildirmake_LDFLAGS=-static ++ ../rfc822/librfc822.la -lcourier-unicode ++maildirmake_LDFLAGS=-static @PCRE_LDFLAGS@ + + testmaildirfilter_SOURCES=maildirfiltertypelist.h testmaildirfilter.c + testmaildirfilter_DEPENDENCIES=libmaildir.la ../numlib/libnumlib.la +-testmaildirfilter_LDADD=libmaildir.la ../numlib/libnumlib.la -lcourier-unicode @LIBPCRE@ +-testmaildirfilter_LDFLAGS=-static ++testmaildirfilter_LDADD=libmaildir.la ../numlib/libnumlib.la -lcourier-unicode ++testmaildirfilter_LDFLAGS=-static @PCRE_LDFLAGS@ + + maildirkwtest_SOURCES=maildirkwtest.c + maildirkwtest_LDADD=libmaildir.la +@@ -141,7 +144,7 @@ clean-local: + + check-am: + @SHELL@ $(srcdir)/testsuite 2>&1 | cmp - $(srcdir)/testsuite.txt +- test "@LIBPCRE@" != "" || exit 0 ; @SHELL@ $(srcdir)/testsuite2 2>&1 | cmp - $(srcdir)/testsuite2.txt ++ test "@PCRE_LDFLAGS@" != "" || exit 0 ; @SHELL@ $(srcdir)/testsuite2 2>&1 | cmp - $(srcdir)/testsuite2.txt + LC_ALL=C; export LC_ALL; ./maildirkwtest | cmp -s - $(srcdir)/maildirkwtest.txt + LC_ALL=C; export LC_ALL; ./maildiraclttest + ./testmaildirsearch iso-8859-1 needle haystack; test $$? = 2 && exit 0; exit 1 +diff --git a/maildir/configure.ac b/maildir/configure.ac +index 946954f..5c2a64c 100644 +--- a/libs/maildir/configure.ac ++++ b/libs/maildir/configure.ac +@@ -47,15 +47,18 @@ dnl Checks for header files. + AC_HEADER_DIRENT + AC_HEADER_STDC + AC_HEADER_TIME +-AC_CHECK_HEADERS(sys/stat.h sys/wait.h fcntl.h unistd.h sysexits.h utime.h pcre.h pcre/pcre.h) ++AC_CHECK_HEADERS(sys/stat.h sys/wait.h fcntl.h unistd.h sysexits.h utime.h) + +-AC_CHECK_HEADER([pcre.h], +- [LIBPCRE=-lpcre]) ++AC_CHECK_PROG(PCRE2, pcre2-config, yes, no) + +-AC_CHECK_HEADER([pcre/pcre.h], +- [LIBPCRE=-lpcre]) +- +-AC_SUBST(LIBPCRE) ++if test "$PCRE2" = "yes" ++then ++ AC_DEFINE_UNQUOTED(HAVE_PCRE2,1,[Whether the pcre library was detected]) ++ PCRE_LDFLAGS="`pcre2-config --libs8`" ++ PCRE_CFLAGS="`pcre2-config --cflags`" ++fi ++AC_SUBST(PCRE_LDFLAGS) ++AC_SUBST(PCRE_CFLAGS) + + AC_HEADER_SYS_WAIT + +diff --git a/maildir/maildirfilter.c b/maildir/maildirfilter.c +index 82702a1..844b051 100644 +--- a/libs/maildir/maildirfilter.c ++++ b/libs/maildir/maildirfilter.c +@@ -26,13 +26,9 @@ + #define EX_SOFTWARE 70 + #endif + +-#if HAVE_PCRE_H +-#include +-#else +-#if HAVE_PCRE_PCRE_H +-#include +-#define HAVE_PCRE_H 1 +-#endif ++#if HAVE_PCRE2 ++#define PCRE2_CODE_UNIT_WIDTH 8 ++#include + #endif + + #if HAVE_SYS_STAT_H +@@ -331,24 +327,25 @@ static int maildir_filter_ruleupdate_utf8(struct maildirfilter *r, + ++c; + } + +-#if HAVE_PCRE_H ++#if HAVE_PCRE2 + switch (type) { + case contains: + case startswith: + case endswith: + { +- const char *errptr; +- int errindex; +- +- pcre *p=pcre_compile(value, PCRE_UTF8, +- &errptr, +- &errindex, +- 0); +- +- +- if (p == NULL) ++ int errcode; ++ PCRE2_SIZE errindex; ++ pcre2_code *pcre_regexp= ++ pcre2_compile((PCRE2_SPTR8)value, ++ PCRE2_ZERO_TERMINATED, ++ PCRE2_UTF, ++ &errcode, ++ &errindex, ++ NULL); ++ ++ if (pcre_regexp == NULL) + return -1; +- pcre_free(p); ++ pcre2_code_free(pcre_regexp); + } + break; + default: +diff --git a/maildrop/configure.ac b/maildrop/configure.ac +index 63acdfb..1c5655f 100644 +--- a/libs/maildrop/configure.ac ++++ b/libs/maildrop/configure.ac +@@ -305,7 +305,7 @@ AC_CHECK_PROG(PCRE2, pcre2-config, yes, no) + + if test "$PCRE2" = "no" + then +- AC_MSG_ERROR([pcre2 library not found]) ++ AC_MSG_ERROR([pcre2-config was not found, please install PCRE2]) + fi + + dnl Try to find sendmail. +-- +2.27.0 diff --git a/maildrop.spec b/maildrop.spec index 5f80f4c..cc064d4 100644 --- a/maildrop.spec +++ b/maildrop.spec @@ -2,15 +2,18 @@ Summary: Mail delivery agent with filtering abilities Name: maildrop Version: 3.0.3 -Release: 1 +Release: 2 License: GPLv2 with exceptions URL: https://sourceforge.net/projects/courier Source0: https://downloads.sourceforge.net/project/courier/%{name}/%{version}/%{name}-%{version}.tar.bz2 Source1: https://downloads.sourceforge.net/project/courier/%{name}/%{version}/%{name}-%{version}.tar.bz2.sig Source2: pubkey.maildrop +Patch0: backport-001-Convert-to-pcre2.patch +Patch1: backport-002-Convert-to-PCRE2.patch + Requires: courier-unicode >= 2.1 -BuildRequires: automake, libtool, autoconf gcc-c++, gdbm-devel, libdb-devel, pcre-devel gawk +BuildRequires: automake, libtool, autoconf gcc-c++, gdbm-devel, libdb-devel, pcre2-devel gawk BuildRequires: gnupg courier-unicode-devel >= 2.1 libidn-devel %description maildrop is the mail filter/mail delivery agent that's used by the @@ -42,6 +45,7 @@ gpg --import %{SOURCE2} gpg --verify %{SOURCE1} %{SOURCE0} %build +autoreconf %configure --disable-shared \ --enable-use-flock=1 --with-locking-method=fcntl \ --enable-use-dotlock=1 \ @@ -76,6 +80,9 @@ cp -pr README README.postfix ChangeLog UPGRADE %{buildroot}%{_defaultdocdir}/%{n %{_mandir}/man8/*.8* %changelog +* Wed Jun 01 2022 gaihuiying - 3.0.3-2 +- switch from pcre to pcre2 + * Thu Dec 16 2021 gaihuiying - 3.0.3-1 - update to 3.0.3