summaryrefslogtreecommitdiff
path: root/regexec.c
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2023-01-19 16:36:05 +0100
committerYves Orton <demerphq@gmail.com>2023-01-20 09:16:20 +0800
commite6f89d6bdb73975a869c4438cdd3501b8edd9a7e (patch)
treec1075829a0997b3cf0be397af491019e0750ecf8 /regexec.c
parent82132a33be4e60debf3133ae86185f29f79dc092 (diff)
downloadperl-e6f89d6bdb73975a869c4438cdd3501b8edd9a7e.tar.gz
regexec.c - harden internals against missing logical_nparens
We can default a 0 rx->logical_nparens to rx->nparens. If rx->logical_nparens is zero then either rx->nparens is also zero, or it can be defaulted. This will fix most re::engine::XXX modules that do not know about the new field, provided they zero the rx structure during construction. If they don't then this patch won't hurt anything and we will have to patch them directly. Also mark re_op_compile() as available to extensions. Marking it as hidden means that re::engine::PCRE2 and others cannot build. This patch should go a long way towards fixing issue #20710.
Diffstat (limited to 'regexec.c')
-rw-r--r--regexec.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/regexec.c b/regexec.c
index 8a54cfa44f..eeaa40e90f 100644
--- a/regexec.c
+++ b/regexec.c
@@ -12011,6 +12011,7 @@ Perl_reg_numbered_buff_fetch_flags(pTHX_ REGEXP * const re, const I32 paren,
SSize_t i,t = 0;
SSize_t s1, t1;
I32 n = paren;
+ I32 logical_nparens = rx->logical_nparens ? rx->logical_nparens : rx->nparens;
PERL_ARGS_ASSERT_REG_NUMBERED_BUFF_FETCH_FLAGS;
@@ -12054,7 +12055,7 @@ Perl_reg_numbered_buff_fetch_flags(pTHX_ REGEXP * const re, const I32 paren,
i = rx->sublen + rx->suboffset - t;
}
else /* when flags is true we do an absolute lookup, and compare against rx->nparens */
- if (inRANGE(n, 0, flags ? (I32)rx->nparens : (I32)rx->logical_nparens)) {
+ if (inRANGE(n, 0, flags ? (I32)rx->nparens : logical_nparens)) {
I32 *map = (!flags && n) ? rx->logical_to_parno : NULL;
I32 true_parno = map ? map[n] : n;
do {
@@ -12141,6 +12142,7 @@ Perl_reg_numbered_buff_length(pTHX_ REGEXP * const r, const SV * const sv,
struct regexp *const rx = ReANY(r);
I32 i;
I32 s1, t1;
+ I32 logical_nparens = rx->logical_nparens ? rx->logical_nparens : rx->nparens;
PERL_ARGS_ASSERT_REG_NUMBERED_BUFF_LENGTH;
@@ -12188,7 +12190,7 @@ Perl_reg_numbered_buff_length(pTHX_ REGEXP * const r, const SV * const sv,
return 0;
default: /* $& / ${^MATCH}, $1, $2, ... */
- if (paren <= (I32)rx->logical_nparens) {
+ if (paren <= logical_nparens) {
I32 true_paren = rx->logical_to_parno
? rx->logical_to_parno[paren]
: paren;