summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYann Ylavic <ylavic@apache.org>2022-02-01 10:51:30 +0000
committerYann Ylavic <ylavic@apache.org>2022-02-01 10:51:30 +0000
commit29412ec3ecbb5f37996b69030f564b86fb19eee7 (patch)
tree98c4b44719f2f8582a3c1728d122335d530bcfcf
parentbca2e9c14ceaf3eb0e11bfe2a0595a9208fee452 (diff)
downloadhttpd-29412ec3ecbb5f37996b69030f564b86fb19eee7.tar.gz
ap_regex: Follow up to r1897240: Fetch the ovector _after_ the match.
Possibly(?) pcre2_match() can modifiy the given pcre2_match_data and invalidate the old ovector, be safe and fetch it after. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1897651 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--server/util_pcre.c24
1 files changed, 6 insertions, 18 deletions
diff --git a/server/util_pcre.c b/server/util_pcre.c
index 68224e7cbf..ff64e3ff17 100644
--- a/server/util_pcre.c
+++ b/server/util_pcre.c
@@ -283,16 +283,12 @@ typedef int* match_vector_pt;
static APR_INLINE
match_data_pt alloc_match_data(apr_size_t size,
- match_vector_pt *ovector,
match_vector_pt small_vector)
{
match_data_pt data;
#ifdef HAVE_PCRE2
data = pcre2_match_data_create(size, NULL);
- if (data) {
- *ovector = pcre2_get_ovector_pointer(data);
- }
#else
if (size > POSIX_MALLOC_THRESHOLD) {
data = malloc(size * sizeof(int) * 3);
@@ -300,7 +296,6 @@ match_data_pt alloc_match_data(apr_size_t size,
else {
data = small_vector;
}
- *ovector = data;
#endif
return data;
@@ -335,7 +330,6 @@ static apr_status_t apreg_tls_cleanup(void *arg)
#endif
static match_data_pt get_match_data(apr_size_t size,
- match_vector_pt *ovector,
match_vector_pt small_vector,
int *to_free)
{
@@ -348,7 +342,7 @@ static match_data_pt get_match_data(apr_size_t size,
current = ap_thread_current();
if (!current) {
*to_free = 1;
- return alloc_match_data(size, ovector, small_vector);
+ return alloc_match_data(size, small_vector);
}
apr_thread_data_get((void **)&tls, "apreg", current);
@@ -383,23 +377,17 @@ static match_data_pt get_match_data(apr_size_t size,
#endif
}
-#ifdef HAVE_PCRE2
- *ovector = pcre2_get_ovector_pointer(tls->data);
-#else
- *ovector = tls->data;
-#endif
return tls->data;
}
#else /* !AP_HAS_THREAD_LOCAL */
static APR_INLINE match_data_pt get_match_data(apr_size_t size,
- match_vector_pt *ovector,
match_vector_pt small_vector,
int *to_free)
{
*to_free = 1;
- return alloc_match_data(size, ovector, small_vector);
+ return alloc_match_data(size, small_vector);
}
#endif /* !AP_HAS_THREAD_LOCAL */
@@ -421,12 +409,10 @@ AP_DECLARE(int) ap_regexec_len(const ap_regex_t *preg, const char *buff,
match_vector_pt ovector = NULL;
apr_size_t ncaps = (apr_size_t)preg->re_nsub + 1;
#ifdef HAVE_PCRE2
- match_data_pt data = get_match_data(ncaps, &ovector, NULL,
- &to_free);
+ match_data_pt data = get_match_data(ncaps, NULL, &to_free);
#else
int small_vector[POSIX_MALLOC_THRESHOLD * 3];
- match_data_pt data = get_match_data(ncaps, &ovector, small_vector,
- &to_free);
+ match_data_pt data = get_match_data(ncaps, small_vector, &to_free);
#endif
if (!data) {
@@ -446,7 +432,9 @@ AP_DECLARE(int) ap_regexec_len(const ap_regex_t *preg, const char *buff,
rc = pcre2_match((const pcre2_code *)preg->re_pcre,
(const unsigned char *)buff, len,
0, options, data, NULL);
+ ovector = pcre2_get_ovector_pointer(data);
#else
+ ovector = data;
rc = pcre_exec((const pcre *)preg->re_pcre, NULL, buff, (int)len,
0, options, ovector, ncaps * 3);
#endif