Blame SOURCES/pcre-8.42-Declare-POSIX-regex-function-names-as-macros-to-PCRE.patch

833ed6
From f1e9a32ee7fad2263636a51536ce0f9f13f09949 Mon Sep 17 00:00:00 2001
833ed6
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
833ed6
Date: Wed, 23 Jan 2019 10:16:20 +0100
833ed6
Subject: [PATCH] Declare POSIX regex function names as macros to PCRE
833ed6
 functions
833ed6
MIME-Version: 1.0
833ed6
Content-Type: text/plain; charset=UTF-8
833ed6
Content-Transfer-Encoding: 8bit
833ed6
833ed6
POSIX regex libraries differ in regex_t size. If a program includes
833ed6
<pcreposix.h>, but is not linked to pcreposix library at run-time
833ed6
(either in effect of --as-needed or a lazy binding in dlopen)
833ed6
other implementation touches memory out of the structure and the
833ed6
program can crash.
833ed6
833ed6
That means once a program includes <pcreposix.h>, it must link to the
833ed6
pcreposix library.
833ed6
833ed6
This patch replaces the POSIX regex declaration with macros to the
833ed6
PCRE uniqely-named function. This ensures that the PCRE's regex_t
833ed6
structure is always handled by the PCRE functions.
833ed6
833ed6
This patch still preserves the POSIX regex definitions in order to
833ed6
preseve ABI with application compiled before this change. The
833ed6
definition can be removed in the future.
833ed6
833ed6
Signed-off-by: Petr Písař <ppisar@redhat.com>
833ed6
---
833ed6
 pcreposix.c | 50 +++++++++++++++++++++++++++++++++++++++++++++-----
833ed6
 pcreposix.h | 20 ++++++++++++++------
833ed6
 2 files changed, 59 insertions(+), 11 deletions(-)
833ed6
833ed6
diff --git a/pcreposix.c b/pcreposix.c
833ed6
index a76d6bf..3f2f3ef 100644
833ed6
--- a/pcreposix.c
833ed6
+++ b/pcreposix.c
833ed6
@@ -39,7 +39,10 @@ POSSIBILITY OF SUCH DAMAGE.
833ed6
 
833ed6
 
833ed6
 /* This module is a wrapper that provides a POSIX API to the underlying PCRE
833ed6
-functions. */
833ed6
+functions. The operative functions are called pcre_regcomp(), etc., with
833ed6
+wrappers that use the plain POSIX names. This makes it easier for an
833ed6
+application to be sure it gets the PCRE versions in the presence of other
833ed6
+POSIX regex libraries. */
833ed6
 
833ed6
 
833ed6
 #ifdef HAVE_CONFIG_H
833ed6
@@ -204,12 +207,49 @@ static const char *const pstring[] = {
833ed6
 
833ed6
 
833ed6
 /*************************************************
833ed6
-*          Translate error code to string        *
833ed6
+*      Wrappers with traditional POSIX names     *
833ed6
 *************************************************/
833ed6
 
833ed6
+/* Keep defining them to preseve ABI with application linked to pcreposix
833ed6
+ * library before they were changed into macros. */
833ed6
+
833ed6
+#undef regerror
833ed6
 PCREPOSIX_EXP_DEFN size_t PCRE_CALL_CONVENTION
833ed6
 regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
833ed6
 {
833ed6
+return pcre_regerror(errcode, preg, errbuf, errbuf_size);
833ed6
+}
833ed6
+
833ed6
+#undef regfree
833ed6
+PCREPOSIX_EXP_DEFN void PCRE_CALL_CONVENTION
833ed6
+regfree(regex_t *preg)
833ed6
+{
833ed6
+pcre_regfree(preg);
833ed6
+}
833ed6
+
833ed6
+#undef regcomp
833ed6
+PCREPOSIX_EXP_DEFN int PCRE_CALL_CONVENTION
833ed6
+regcomp(regex_t *preg, const char *pattern, int cflags)
833ed6
+{
833ed6
+return pcre_regcomp(preg, pattern, cflags);
833ed6
+}
833ed6
+
833ed6
+#undef regexec
833ed6
+PCREPOSIX_EXP_DEFN int PCRE_CALL_CONVENTION
833ed6
+regexec(const regex_t *preg, const char *string, size_t nmatch,
833ed6
+  regmatch_t pmatch[], int eflags)
833ed6
+{
833ed6
+return pcre_regexec(preg, string, nmatch, pmatch, eflags);
833ed6
+}
833ed6
+
833ed6
+
833ed6
+/*************************************************
833ed6
+*          Translate error code to string        *
833ed6
+*************************************************/
833ed6
+
833ed6
+PCREPOSIX_EXP_DEFN size_t PCRE_CALL_CONVENTION
833ed6
+pcre_regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
833ed6
+{
833ed6
 const char *message, *addmessage;
833ed6
 size_t length, addlength;
833ed6
 
833ed6
@@ -243,7 +283,7 @@ return length + addlength;
833ed6
 *************************************************/
833ed6
 
833ed6
 PCREPOSIX_EXP_DEFN void PCRE_CALL_CONVENTION
833ed6
-regfree(regex_t *preg)
833ed6
+pcre_regfree(regex_t *preg)
833ed6
 {
833ed6
 (PUBL(free))(preg->re_pcre);
833ed6
 }
833ed6
@@ -266,7 +306,7 @@ Returns:      0 on success
833ed6
 */
833ed6
 
833ed6
 PCREPOSIX_EXP_DEFN int PCRE_CALL_CONVENTION
833ed6
-regcomp(regex_t *preg, const char *pattern, int cflags)
833ed6
+pcre_regcomp(regex_t *preg, const char *pattern, int cflags)
833ed6
 {
833ed6
 const char *errorptr;
833ed6
 int erroffset;
833ed6
@@ -320,7 +360,7 @@ be set. When this is the case, the nmatch and pmatch arguments are ignored, and
833ed6
 the only result is yes/no/error. */
833ed6
 
833ed6
 PCREPOSIX_EXP_DEFN int PCRE_CALL_CONVENTION
833ed6
-regexec(const regex_t *preg, const char *string, size_t nmatch,
833ed6
+pcre_regexec(const regex_t *preg, const char *string, size_t nmatch,
833ed6
   regmatch_t pmatch[], int eflags)
833ed6
 {
833ed6
 int rc, so, eo;
833ed6
diff --git a/pcreposix.h b/pcreposix.h
833ed6
index c77c0b0..6f108b8 100644
833ed6
--- a/pcreposix.h
833ed6
+++ b/pcreposix.h
833ed6
@@ -131,13 +131,21 @@ file. */
833ed6
 #  endif
833ed6
 #endif
833ed6
 
833ed6
-/* The functions */
833ed6
-
833ed6
-PCREPOSIX_EXP_DECL int regcomp(regex_t *, const char *, int);
833ed6
-PCREPOSIX_EXP_DECL int regexec(const regex_t *, const char *, size_t,
833ed6
+/* The functions. The actual code is in functions with pcre_xxx names for
833ed6
+uniqueness. POSIX names are provided for API compatibility with POSIX regex
833ed6
+functions. It's done this way to ensure to they are always get from the
833ed6
+PCRE library and not by accident from elsewhere. (regex_t differs in size
833ed6
+elsewhere.) */
833ed6
+
833ed6
+PCREPOSIX_EXP_DECL int pcre_regcomp(regex_t *, const char *, int);
833ed6
+#define regcomp pcre_regcomp
833ed6
+PCREPOSIX_EXP_DECL int pcre_regexec(const regex_t *, const char *, size_t,
833ed6
                      regmatch_t *, int);
833ed6
-PCREPOSIX_EXP_DECL size_t regerror(int, const regex_t *, char *, size_t);
833ed6
-PCREPOSIX_EXP_DECL void regfree(regex_t *);
833ed6
+#define regexec pcre_regexec
833ed6
+PCREPOSIX_EXP_DECL size_t pcre_regerror(int, const regex_t *, char *, size_t);
833ed6
+#define regerror pcre_regerror
833ed6
+PCREPOSIX_EXP_DECL void pcre_regfree(regex_t *);
833ed6
+#define regfree pcre_regfree
833ed6
 
833ed6
 #ifdef __cplusplus
833ed6
 }   /* extern "C" */
833ed6
-- 
833ed6
2.17.2
833ed6