git://git.exim.org
/
exim.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use non-releasable memory for regex line-buffer
[exim.git]
/
src
/
src
/
regex.c
diff --git
a/src/src/regex.c
b/src/src/regex.c
index cda807716832d178d188f8c1dc3d226fcf0347d5..642b9cf9322f324ba0db9cbccde7537e6a47490b 100644
(file)
--- a/
src/src/regex.c
+++ b/
src/src/regex.c
@@
-24,8
+24,6
@@
typedef struct pcre_list {
struct pcre_list * next;
} pcre_list;
struct pcre_list * next;
} pcre_list;
-uschar regex_match_string_buffer[1024];
-
extern FILE *mime_stream;
extern uschar *mime_current_boundary;
extern FILE *mime_stream;
extern uschar *mime_current_boundary;
@@
-63,6
+61,13
@@
if (cntp) *cntp = cnt;
return re_list_head;
}
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)
{
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)
{
/* 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++)
{
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);
}
regex_vars[nn-1] = string_copyn(linebuffer + ovec[off], len);
}
+ store_pool = save_pool;
return OK;
}
}
return OK;
}
}
@@
-111,7
+118,6
@@
regex(const uschar ** listptr, BOOL cacheable)
unsigned long mbox_size;
FILE * mbox_file;
pcre_list * re_list_head;
unsigned long mbox_size;
FILE * mbox_file;
pcre_list * re_list_head;
-uschar * linebuffer;
long f_pos = 0;
int ret = FAIL, cnt, lcount = REGEX_LOOPCOUNT_STORE_RESET;
rmark reset_point;
long f_pos = 0;
int ret = FAIL, cnt, lcount = REGEX_LOOPCOUNT_STORE_RESET;
rmark reset_point;
@@
-144,16
+150,15
@@
reset_point = store_mark();
if ((re_list_head = compile(*listptr, cacheable, &cnt)))
{
/* match each line against all regexes */
if ((re_list_head = compile(*listptr, cacheable, &cnt)))
{
/* match each line against all regexes */
- linebuffer = store_get(32767, GET_TAINTED);
- while (fgets(CS linebuffer, 32767, mbox_file))
+ while (fgets(CS big_buffer, big_buffer_size, mbox_file))
{
if ( mime_stream && mime_current_boundary /* check boundary */
{
if ( mime_stream && mime_current_boundary /* check boundary */
- && Ustrncmp(
line
buffer, "--", 2) == 0
- && Ustrncmp((
line
buffer+2), mime_current_boundary,
+ && Ustrncmp(
big_
buffer, "--", 2) == 0
+ && Ustrncmp((
big_
buffer+2), mime_current_boundary,
Ustrlen(mime_current_boundary)) == 0)
break; /* found boundary */
Ustrlen(mime_current_boundary)) == 0)
break; /* found boundary */
- if ((ret = matcher(re_list_head,
linebuffer, (int)Ustrlen(line
buffer))) == OK)
+ if ((ret = matcher(re_list_head,
big_buffer, (int)Ustrlen(big_
buffer))) == OK)
break;
if ((lcount -= cnt) <= 0)
break;
if ((lcount -= cnt) <= 0)