pcre2/pcre2-10.32-Declare-POSIX-regex-function-names-as-macros-to-PCRE.patch

131 lines
4.9 KiB
Diff
Raw Normal View History

From 3450125e8bfd7afd7eedadabac86575f74e28a06 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Tue, 22 Jan 2019 15:12:31 +0100
Subject: [PATCH] Declare POSIX regex function names as macros to PCRE
functions
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
POSIX regex libraries differ in regex_t size. If a program includes
<pcreposix.h>, but is not linked to pcreposix library at run-time
(either in effect of --as-needed or a lazy binding in dlopen)
other implementation touches memory out of the structure and the
program can crash.
That means once a program includes <pcreposix.h>, it must link to the
pcreposix library.
This patch replaces the POSIX regex declaration with macros to the
PCRE uniqely-named function. This ensures that the PCRE's regex_t
structure is always handled by the PCRE functions.
This patch still preserves the POSIX regex definitions in order to
preseve ABI with application compiled before this change. The
definition can be removed in the future.
Signed-off-by: Petr Písař <ppisar@redhat.com>
---
README | 12 ------------
src/pcre2posix.c | 7 +++++++
src/pcre2posix.h | 15 ++++++++-------
3 files changed, 15 insertions(+), 19 deletions(-)
diff --git a/README b/README
index 9c46ac4..b44392a 100644
--- a/README
+++ b/README
@@ -55,18 +55,6 @@ with existing files of that name by distributing it that way. To use PCRE2 with
an existing program that uses the POSIX API, pcre2posix.h will have to be
renamed or pointed at by a link (or the program modified, of course).
-If you are using the POSIX interface to PCRE2 and there is already a POSIX
-regex library installed on your system, as well as worrying about the regex.h
-header file (as mentioned above), you must also take care when linking programs
-to ensure that they link with PCRE2's libpcre2-posix library. Otherwise they
-may pick up the POSIX functions of the same name from the other library.
-
-To help with this issue, the libpcre2-posix library provides alternative names
-for the POSIX functions. These are the POSIX names, prefixed with "pcre2_", for
-example, pcre2_regcomp(). If an application can be compiled to use the
-alternative names (for example by the use of -Dregcomp=pcre2_regcomp etc.) it
-can be sure of linking with the PCRE2 functions.
-
Documentation for PCRE2
-----------------------
diff --git a/src/pcre2posix.c b/src/pcre2posix.c
index 3666100..1f382fa 100644
--- a/src/pcre2posix.c
+++ b/src/pcre2posix.c
@@ -177,24 +177,31 @@ static const char *const pstring[] = {
* Wrappers with traditional POSIX names *
*************************************************/
+/* Keep defining them to preseve ABI with application linked to pcre2-posix
+ * library before they were changed into macros. */
+
+#undef regerror
PCRE2POSIX_EXP_DEFN size_t PCRE2_CALL_CONVENTION
regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
{
return pcre2_regerror(errcode, preg, errbuf, errbuf_size);
}
+#undef regfree
PCRE2POSIX_EXP_DEFN void PCRE2_CALL_CONVENTION
regfree(regex_t *preg)
{
pcre2_regfree(preg);
}
+#undef regcomp
PCRE2POSIX_EXP_DEFN int PCRE2_CALL_CONVENTION
regcomp(regex_t *preg, const char *pattern, int cflags)
{
return pcre2_regcomp(preg, pattern, cflags);
}
+#undef regexec
PCRE2POSIX_EXP_DEFN int PCRE2_CALL_CONVENTION
regexec(const regex_t *preg, const char *string, size_t nmatch,
regmatch_t pmatch[], int eflags)
diff --git a/src/pcre2posix.h b/src/pcre2posix.h
index bfe347e..b296df9 100644
--- a/src/pcre2posix.h
+++ b/src/pcre2posix.h
@@ -139,22 +139,23 @@ file. */
#endif
/* The functions. The actual code is in functions with pcre2_xxx names for
-uniqueness. Wrappers with the POSIX names are provided for those who can ensure
-they get them from the PCRE2 library and not by accident from elsewhere. */
+uniqueness. POSIX names are provided for API compatibility with POSIX regex
+functions. It's done this way to ensure to they are always get from the
+PCRE2 library and not by accident from elsewhere. (regex_t differs in size
+elsewhere.) */
PCRE2POSIX_EXP_DECL int pcre2_regcomp(regex_t *, const char *, int);
-PCRE2POSIX_EXP_DECL int regcomp(regex_t *, const char *, int);
+#define regcomp pcre2_regcomp
PCRE2POSIX_EXP_DECL int pcre2_regexec(const regex_t *, const char *, size_t,
regmatch_t *, int);
-PCRE2POSIX_EXP_DECL int regexec(const regex_t *, const char *, size_t,
- regmatch_t *, int);
+#define regexec pcre2_regexec
PCRE2POSIX_EXP_DECL size_t pcre2_regerror(int, const regex_t *, char *, size_t);
-PCRE2POSIX_EXP_DECL size_t regerror(int, const regex_t *, char *, size_t);
+#define regerror pcre2_regerror
PCRE2POSIX_EXP_DECL void pcre2_regfree(regex_t *);
-PCRE2POSIX_EXP_DECL void regfree(regex_t *);
+#define regfree pcre2_regfree
#ifdef __cplusplus
} /* extern "C" */
--
2.17.2