475 |
|
|
476 |
|
|
477 |
/************************************************* |
/************************************************* |
478 |
|
* Check match or recursion limit * |
479 |
|
*************************************************/ |
480 |
|
|
481 |
|
static int |
482 |
|
check_match_limit(pcre *re, pcre_extra *extra, uschar *bptr, int len, |
483 |
|
int start_offset, int options, int *use_offsets, int use_size_offsets, |
484 |
|
int flag, unsigned long int *limit, int errnumber, const char *msg) |
485 |
|
{ |
486 |
|
int count; |
487 |
|
int min = 0; |
488 |
|
int mid = 64; |
489 |
|
int max = -1; |
490 |
|
|
491 |
|
extra->flags |= flag; |
492 |
|
|
493 |
|
for (;;) |
494 |
|
{ |
495 |
|
*limit = mid; |
496 |
|
|
497 |
|
count = pcre_exec(re, extra, (char *)bptr, len, start_offset, options, |
498 |
|
use_offsets, use_size_offsets); |
499 |
|
|
500 |
|
if (count == errnumber) |
501 |
|
{ |
502 |
|
/* fprintf(outfile, "Testing %s limit = %d\n", msg, mid); */ |
503 |
|
min = mid; |
504 |
|
mid = (mid == max - 1)? max : (max > 0)? (min + max)/2 : mid*2; |
505 |
|
} |
506 |
|
|
507 |
|
else if (count >= 0 || count == PCRE_ERROR_NOMATCH || |
508 |
|
count == PCRE_ERROR_PARTIAL) |
509 |
|
{ |
510 |
|
if (mid == min + 1) |
511 |
|
{ |
512 |
|
fprintf(outfile, "Minimum %s limit = %d\n", msg, mid); |
513 |
|
break; |
514 |
|
} |
515 |
|
/* fprintf(outfile, "Testing %s limit = %d\n", msg, mid); */ |
516 |
|
max = mid; |
517 |
|
mid = (min + mid)/2; |
518 |
|
} |
519 |
|
else break; /* Some other error */ |
520 |
|
} |
521 |
|
|
522 |
|
extra->flags &= ~flag; |
523 |
|
return count; |
524 |
|
} |
525 |
|
|
526 |
|
|
527 |
|
|
528 |
|
/************************************************* |
529 |
* Main Program * |
* Main Program * |
530 |
*************************************************/ |
*************************************************/ |
531 |
|
|
542 |
int timeit = 0; |
int timeit = 0; |
543 |
int showinfo = 0; |
int showinfo = 0; |
544 |
int showstore = 0; |
int showstore = 0; |
545 |
|
int quiet = 0; |
546 |
int size_offsets = 45; |
int size_offsets = 45; |
547 |
int size_offsets_max; |
int size_offsets_max; |
548 |
int *offsets = NULL; |
int *offsets = NULL; |
583 |
if (strcmp(argv[op], "-s") == 0 || strcmp(argv[op], "-m") == 0) |
if (strcmp(argv[op], "-s") == 0 || strcmp(argv[op], "-m") == 0) |
584 |
showstore = 1; |
showstore = 1; |
585 |
else if (strcmp(argv[op], "-t") == 0) timeit = 1; |
else if (strcmp(argv[op], "-t") == 0) timeit = 1; |
586 |
|
else if (strcmp(argv[op], "-q") == 0) quiet = 1; |
587 |
else if (strcmp(argv[op], "-i") == 0) showinfo = 1; |
else if (strcmp(argv[op], "-i") == 0) showinfo = 1; |
588 |
else if (strcmp(argv[op], "-d") == 0) showinfo = debug = 1; |
else if (strcmp(argv[op], "-d") == 0) showinfo = debug = 1; |
589 |
#if !defined NODFA |
#if !defined NODFA |
616 |
printf(" POSIX malloc threshold = %d\n", rc); |
printf(" POSIX malloc threshold = %d\n", rc); |
617 |
(void)pcre_config(PCRE_CONFIG_MATCH_LIMIT, &rc); |
(void)pcre_config(PCRE_CONFIG_MATCH_LIMIT, &rc); |
618 |
printf(" Default match limit = %d\n", rc); |
printf(" Default match limit = %d\n", rc); |
619 |
|
(void)pcre_config(PCRE_CONFIG_MATCH_LIMIT_RECURSION, &rc); |
620 |
|
printf(" Default recursion depth limit = %d\n", rc); |
621 |
(void)pcre_config(PCRE_CONFIG_STACKRECURSE, &rc); |
(void)pcre_config(PCRE_CONFIG_STACKRECURSE, &rc); |
622 |
printf(" Match recursion uses %s\n", rc? "stack" : "heap"); |
printf(" Match recursion uses %s\n", rc? "stack" : "heap"); |
623 |
exit(0); |
exit(0); |
689 |
pcre_stack_malloc = stack_malloc; |
pcre_stack_malloc = stack_malloc; |
690 |
pcre_stack_free = stack_free; |
pcre_stack_free = stack_free; |
691 |
|
|
692 |
/* Heading line, then prompt for first regex if stdin */ |
/* Heading line unless quiet, then prompt for first regex if stdin */ |
693 |
|
|
694 |
fprintf(outfile, "PCRE version %s\n\n", pcre_version()); |
if (!quiet) fprintf(outfile, "PCRE version %s\n\n", pcre_version()); |
695 |
|
|
696 |
/* Main loop */ |
/* Main loop */ |
697 |
|
|
951 |
if ((options & PCRE_CASELESS) != 0) cflags |= REG_ICASE; |
if ((options & PCRE_CASELESS) != 0) cflags |= REG_ICASE; |
952 |
if ((options & PCRE_MULTILINE) != 0) cflags |= REG_NEWLINE; |
if ((options & PCRE_MULTILINE) != 0) cflags |= REG_NEWLINE; |
953 |
if ((options & PCRE_DOTALL) != 0) cflags |= REG_DOTALL; |
if ((options & PCRE_DOTALL) != 0) cflags |= REG_DOTALL; |
954 |
|
if ((options & PCRE_NO_AUTO_CAPTURE) != 0) cflags |= REG_NOSUB; |
955 |
|
if ((options & PCRE_UTF8) != 0) cflags |= REG_UTF8; |
956 |
|
|
957 |
rc = regcomp(&preg, (char *)p, cflags); |
rc = regcomp(&preg, (char *)p, cflags); |
958 |
|
|
959 |
/* Compilation failed; go back for another re, skipping to blank line |
/* Compilation failed; go back for another re, skipping to blank line |
1169 |
fprintf(outfile, "Partial matching not supported\n"); |
fprintf(outfile, "Partial matching not supported\n"); |
1170 |
|
|
1171 |
if (get_options == 0) fprintf(outfile, "No options\n"); |
if (get_options == 0) fprintf(outfile, "No options\n"); |
1172 |
else fprintf(outfile, "Options:%s%s%s%s%s%s%s%s%s%s%s\n", |
else fprintf(outfile, "Options:%s%s%s%s%s%s%s%s%s%s%s%s\n", |
1173 |
((get_options & PCRE_ANCHORED) != 0)? " anchored" : "", |
((get_options & PCRE_ANCHORED) != 0)? " anchored" : "", |
1174 |
((get_options & PCRE_CASELESS) != 0)? " caseless" : "", |
((get_options & PCRE_CASELESS) != 0)? " caseless" : "", |
1175 |
((get_options & PCRE_EXTENDED) != 0)? " extended" : "", |
((get_options & PCRE_EXTENDED) != 0)? " extended" : "", |
1179 |
((get_options & PCRE_DOLLAR_ENDONLY) != 0)? " dollar_endonly" : "", |
((get_options & PCRE_DOLLAR_ENDONLY) != 0)? " dollar_endonly" : "", |
1180 |
((get_options & PCRE_EXTRA) != 0)? " extra" : "", |
((get_options & PCRE_EXTRA) != 0)? " extra" : "", |
1181 |
((get_options & PCRE_UNGREEDY) != 0)? " ungreedy" : "", |
((get_options & PCRE_UNGREEDY) != 0)? " ungreedy" : "", |
1182 |
|
((get_options & PCRE_NO_AUTO_CAPTURE) != 0)? " no_auto_capture" : "", |
1183 |
((get_options & PCRE_UTF8) != 0)? " utf8" : "", |
((get_options & PCRE_UTF8) != 0)? " utf8" : "", |
1184 |
((get_options & PCRE_NO_UTF8_CHECK) != 0)? " no_utf8_check" : ""); |
((get_options & PCRE_NO_UTF8_CHECK) != 0)? " no_utf8_check" : ""); |
1185 |
|
|
1325 |
|
|
1326 |
for (;;) |
for (;;) |
1327 |
{ |
{ |
1328 |
unsigned char *q; |
uschar *q; |
1329 |
unsigned char *bptr = dbuffer; |
uschar *bptr = dbuffer; |
1330 |
int *use_offsets = offsets; |
int *use_offsets = offsets; |
1331 |
int use_size_offsets = size_offsets; |
int use_size_offsets = size_offsets; |
1332 |
int callout_data = 0; |
int callout_data = 0; |
1614 |
(void)regerror(rc, &preg, (char *)buffer, BUFFER_SIZE); |
(void)regerror(rc, &preg, (char *)buffer, BUFFER_SIZE); |
1615 |
fprintf(outfile, "No match: POSIX code %d: %s\n", rc, buffer); |
fprintf(outfile, "No match: POSIX code %d: %s\n", rc, buffer); |
1616 |
} |
} |
1617 |
|
else if ((((const pcre *)preg.re_pcre)->options & PCRE_NO_AUTO_CAPTURE) |
1618 |
|
!= 0) |
1619 |
|
{ |
1620 |
|
fprintf(outfile, "Matched with REG_NOSUB\n"); |
1621 |
|
} |
1622 |
else |
else |
1623 |
{ |
{ |
1624 |
size_t i; |
size_t i; |
1679 |
} |
} |
1680 |
|
|
1681 |
/* If find_match_limit is set, we want to do repeated matches with |
/* If find_match_limit is set, we want to do repeated matches with |
1682 |
varying limits in order to find the minimum value. */ |
varying limits in order to find the minimum value for the match limit and |
1683 |
|
for the recursion limit. */ |
1684 |
|
|
1685 |
if (find_match_limit) |
if (find_match_limit) |
1686 |
{ |
{ |
|
int min = 0; |
|
|
int mid = 64; |
|
|
int max = -1; |
|
|
|
|
1687 |
if (extra == NULL) |
if (extra == NULL) |
1688 |
{ |
{ |
1689 |
extra = (pcre_extra *)malloc(sizeof(pcre_extra)); |
extra = (pcre_extra *)malloc(sizeof(pcre_extra)); |
1690 |
extra->flags = 0; |
extra->flags = 0; |
1691 |
} |
} |
|
extra->flags |= PCRE_EXTRA_MATCH_LIMIT; |
|
|
|
|
|
for (;;) |
|
|
{ |
|
|
extra->match_limit = mid; |
|
|
count = pcre_exec(re, extra, (char *)bptr, len, start_offset, |
|
|
options | g_notempty, use_offsets, use_size_offsets); |
|
|
if (count == PCRE_ERROR_MATCHLIMIT) |
|
|
{ |
|
|
/* fprintf(outfile, "Testing match limit = %d\n", mid); */ |
|
|
min = mid; |
|
|
mid = (mid == max - 1)? max : (max > 0)? (min + max)/2 : mid*2; |
|
|
} |
|
|
else if (count >= 0 || count == PCRE_ERROR_NOMATCH || |
|
|
count == PCRE_ERROR_PARTIAL) |
|
|
{ |
|
|
if (mid == min + 1) |
|
|
{ |
|
|
fprintf(outfile, "Minimum match limit = %d\n", mid); |
|
|
break; |
|
|
} |
|
|
/* fprintf(outfile, "Testing match limit = %d\n", mid); */ |
|
|
max = mid; |
|
|
mid = (min + mid)/2; |
|
|
} |
|
|
else break; /* Some other error */ |
|
|
} |
|
1692 |
|
|
1693 |
extra->flags &= ~PCRE_EXTRA_MATCH_LIMIT; |
count = check_match_limit(re, extra, bptr, len, start_offset, |
1694 |
|
options|g_notempty, use_offsets, use_size_offsets, |
1695 |
|
PCRE_EXTRA_MATCH_LIMIT, &(extra->match_limit), |
1696 |
|
PCRE_ERROR_MATCHLIMIT, "match()"); |
1697 |
|
|
1698 |
|
count = check_match_limit(re, extra, bptr, len, start_offset, |
1699 |
|
options|g_notempty, use_offsets, use_size_offsets, |
1700 |
|
PCRE_EXTRA_MATCH_LIMIT_RECURSION, &(extra->match_limit_recursion), |
1701 |
|
PCRE_ERROR_RECURSIONLIMIT, "match() recursion"); |
1702 |
} |
} |
1703 |
|
|
1704 |
/* If callout_data is set, use the interface with additional data */ |
/* If callout_data is set, use the interface with additional data */ |