From 2a0faa2114d5f0cef2b1281ec7400125644e367d Mon Sep 17 00:00:00 2001 From: "Philip.Hazel" Date: Tue, 15 Oct 2019 10:46:36 +0000 Subject: [PATCH] Ensure regexec is thread safe to avoid sanitizer warnings. --- ChangeLog | 4 ++++ src/pcre2posix.c | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index d584ab2..e5973c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -170,6 +170,10 @@ value (because the search for a "required" code unit starts at the match start for non-unique first code unit patterns, but after a unique first code unit, and patterns such as a*a need the former action). +36. Small patch to pcre2posix.c to set the erroroffset field to -1 immediately +after a successful compile, instead of at the start of matching to avoid a +sanitizer complaint (regexec is supposed to be thread safe). + Version 10.33 16-April-2019 --------------------------- diff --git a/src/pcre2posix.c b/src/pcre2posix.c index 34a8d80..b24620a 100644 --- a/src/pcre2posix.c +++ b/src/pcre2posix.c @@ -323,6 +323,7 @@ if (preg->re_pcre2_code == NULL) PCRE2_INFO_CAPTURECOUNT, &re_nsub); preg->re_nsub = (size_t)re_nsub; preg->re_match_data = pcre2_match_data_create(re_nsub + 1, NULL); +preg->re_erroffset = (size_t)(-1); /* No meaning after successful compile */ if (preg->re_match_data == NULL) { @@ -356,8 +357,6 @@ if ((eflags & REG_NOTBOL) != 0) options |= PCRE2_NOTBOL; if ((eflags & REG_NOTEOL) != 0) options |= PCRE2_NOTEOL; if ((eflags & REG_NOTEMPTY) != 0) options |= PCRE2_NOTEMPTY; -((regex_t *)preg)->re_erroffset = (size_t)(-1); /* Only has meaning after compile */ - /* When REG_NOSUB was specified, or if no vector has been passed in which to put captured strings, ensure that nmatch is zero. This will stop any attempt to write to pmatch. */