diff options
author | Jeremy Harris <jgh146exb@wizmail.org> | 2022-11-11 18:22:00 +0000 |
---|---|---|
committer | Jeremy Harris <jgh146exb@wizmail.org> | 2022-11-11 19:52:19 +0000 |
commit | 7ad1a2b2cc57b5f4bcb59186a9a8abcbed9f4f76 (patch) | |
tree | 5872f7fd3de6384f962d5480d88f3501bbaa624c /src | |
parent | e63825824cc406c160ccbf2b154c5d81b168604a (diff) |
Fix regex substring capture variables for null matches (again). Bug 2933
Broken-by: 59d66fdc13f0
Diffstat (limited to 'src')
-rw-r--r-- | src/src/exim.c | 11 | ||||
-rw-r--r-- | src/src/malware.c | 10 | ||||
-rw-r--r-- | src/src/regex.c | 8 |
3 files changed, 14 insertions, 15 deletions
diff --git a/src/src/exim.c b/src/src/exim.c index 47a685aa7..16c0184e0 100644 --- a/src/src/exim.c +++ b/src/src/exim.c @@ -127,16 +127,15 @@ BOOL yield; if ((yield = (res >= 0))) { + PCRE2_SIZE * ovec = pcre2_get_ovector_pointer(md); res = pcre2_get_ovector_count(md); expand_nmax = setup < 0 ? 0 : setup + 1; for (int matchnum = setup < 0 ? 0 : 1; matchnum < res; matchnum++) { - PCRE2_SIZE len; - pcre2_substring_get_bynumber(md, matchnum, - (PCRE2_UCHAR **)&expand_nstring[expand_nmax], &len); - if (!expand_nstring[expand_nmax]) - { expand_nstring[expand_nmax] = US""; len = 0; } - expand_nlength[expand_nmax++] = (int)len; + int off = matchnum * 2; + int len = ovec[off + 1] - ovec[off]; + expand_nstring[expand_nmax] = string_copyn(subject + ovec[off], len); + expand_nlength[expand_nmax++] = len; } expand_nmax--; } diff --git a/src/src/malware.c b/src/src/malware.c index 423a5b692..01dd455ba 100644 --- a/src/src/malware.c +++ b/src/src/malware.c @@ -310,16 +310,16 @@ m_pcre_exec(const pcre2_code * cre, uschar * text) { pcre2_match_data * md = pcre2_match_data_create(2, pcre_gen_ctx); int i = pcre2_match(cre, text, PCRE2_ZERO_TERMINATED, 0, 0, md, pcre_gen_mtc_ctx); -PCRE2_UCHAR * substr = NULL; -PCRE2_SIZE slen; +uschar * substr = NULL; if (i >= 2) /* Got it */ { - pcre2_substring_get_bynumber(md, 1, &substr, &slen); /* uses same ctx as md */ - if (!substr) substr = US""; + PCRE2_SIZE * ovec = pcre2_get_ovector_pointer(md); + int len = ovec[3] - ovec[2]; + substr = string_copyn(text + ovec[2], len); } /* pcre2_match_data_free(md); gen ctx needs no free */ -return US substr; +return substr; } static const pcre2_code * diff --git a/src/src/regex.c b/src/src/regex.c index b401ba0d7..210620f26 100644 --- a/src/src/regex.c +++ b/src/src/regex.c @@ -79,10 +79,10 @@ for (pcre_list * ri = re_list_head; ri; ri = ri->next) for (int nn = 1; nn < n; nn++) { - PCRE2_UCHAR * cstr; - PCRE2_SIZE cslen; - pcre2_substring_get_bynumber(md, nn, &cstr, &cslen); /* uses same ctx as md */ - regex_vars[nn-1] = cstr ? CUS cstr : CUS""; + PCRE2_SIZE * ovec = pcre2_get_ovector_pointer(md); + int off = nn * 2; + int len = ovec[off + 1] - ovec[off]; + regex_vars[nn-1] = string_copyn(linebuffer + ovec[off], len); } return OK; |