[exim-cvs] Use non-releaseable memory for regex match string…

Inizio della pagina
Delete this message
Reply to this message
Autore: Exim Git Commits Mailing List
Data:  
To: exim-cvs
Oggetto: [exim-cvs] Use non-releaseable memory for regex match strings. Bug 3047
Gitweb: https://git.exim.org/exim.git/commitdiff/84add256b3467cf6e0d4a2edf72cf5bf16cd9306
Commit:     84add256b3467cf6e0d4a2edf72cf5bf16cd9306
Parent:     cd8cb71deb2d653228cc037cf91ecab980acdcd0
Author:     Jeremy Harris <jgh146exb@???>
AuthorDate: Sun Feb 11 13:57:18 2024 +0000
Committer:  Jeremy Harris <jgh146exb@???>
CommitDate: Sun Feb 11 14:03:41 2024 +0000


    Use non-releaseable memory for regex match strings. Bug 3047


    Broken-by: 35aacb69f5c8
---
 src/src/regex.c | 11 +++++++++++
 1 file changed, 11 insertions(+)


diff --git a/src/src/regex.c b/src/src/regex.c
index cda807716..bb34e5b23 100644
--- a/src/src/regex.c
+++ b/src/src/regex.c
@@ -63,6 +63,13 @@ if (cntp) *cntp = cnt;
return re_list_head;
}

+
+/* Check list of REs against buffer, returning OK for (first) match,
+else FAIL.  On match return allocated result strings in regex_vars[]. 
+
+We use the perm-pool for that, so that our caller can release
+other allocations.
+*/
 static int
 matcher(pcre_list * re_list_head, uschar * linebuffer, int len)
 {
@@ -75,6 +82,9 @@ for (pcre_list * ri = re_list_head; ri; ri = ri->next)
   /* try matcher on the line */
   if ((n = pcre2_match(ri->re, (PCRE2_SPTR)linebuffer, len, 0, 0, md, pcre_gen_mtc_ctx)) > 0)
     {
+    int save_pool = store_pool;
+    store_pool = POOL_PERM;
+
     Ustrncpy(regex_match_string_buffer, ri->pcre_text,
           sizeof(regex_match_string_buffer)-1);
     regex_match_string = regex_match_string_buffer;
@@ -87,6 +97,7 @@ for (pcre_list * ri = re_list_head; ri; ri = ri->next)
       regex_vars[nn-1] = string_copyn(linebuffer + ovec[off], len);
       }


+    store_pool = save_pool;
     return OK;
     }
   }


--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-cvs.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-cvs-unsubscribe@???
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/