use dynamic mem for regex_match_string
[exim.git] / src / src / regex.c
index cda807716832d178d188f8c1dc3d226fcf0347d5..d5dc1025852eda58eff36fe78efed2f98dce7f12 100644 (file)
@@ -24,8 +24,6 @@ typedef struct pcre_list {
   struct pcre_list *   next;
 } pcre_list;
 
-uschar regex_match_string_buffer[1024];
-
 extern FILE *mime_stream;
 extern uschar *mime_current_boundary;
 
@@ -63,6 +61,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,9 +80,10 @@ 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)
     {
-    Ustrncpy(regex_match_string_buffer, ri->pcre_text,
-             sizeof(regex_match_string_buffer)-1);
-    regex_match_string = regex_match_string_buffer;
+    int save_pool = store_pool;
+    store_pool = POOL_PERM;
+
+    regex_match_string = string_copy(ri->pcre_text);
 
     for (int nn = 1; nn < n; nn++)
       {
@@ -87,6 +93,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;
     }
   }