Skip to content

Commit

Permalink
Fix pattern matching crash on windows.
Browse files Browse the repository at this point in the history
When we use the fallback bregex code we cannot use a nmatch == 0 and
pmatch == NULL as we can with regular regexec on UNIX nowadays.

One day we might want to teach this fall back code how things work in
reality in the real world now but for now we work around it.

From the current manpage on Solaris on regexec:

If nmatch is zero or REG_NOSUB was set in the cflags argument
to regcomp(), then regexec() will ignore the pmatch argument.
Otherwise, the pmatch argument must point to an array with at
least nmatch elements, and regexec() will fill in the elements
of that array with offsets of the substrings of string that
correspond to the parenthesised subexpressions of pattern.
  • Loading branch information
Marco van Wieringen committed Sep 15, 2015
1 parent f05dcbb commit 51e3360
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/dird/ua_acl.c
Expand Up @@ -44,6 +44,8 @@ static inline bool find_in_acl_list(alist *list, int acl, const char *item, int
{
int rc;
regex_t preg;
const int nmatch = 30;
regmatch_t pmatch[nmatch];
bool retval = false;
const char *list_value;

Expand Down Expand Up @@ -92,7 +94,7 @@ static inline bool find_in_acl_list(alist *list, int acl, const char *item, int
continue;
}

if (regexec(&preg, item, 0, NULL, 0) == 0) {
if (regexec(&preg, item, nmatch, pmatch, 0) == 0) {
Dmsg3(1400, "ACL found %s in %d using regex %s\n", item, acl, list_value);
regfree(&preg);
goto bail_out;
Expand Down Expand Up @@ -127,7 +129,7 @@ static inline bool find_in_acl_list(alist *list, int acl, const char *item, int
continue;
}

if (regexec(&preg, item, 0, NULL, 0) == 0) {
if (regexec(&preg, item, nmatch, pmatch, 0) == 0) {
Dmsg3(1400, "ACL found %s in %d using regex %s\n", item, acl, list_value);
retval = true;
regfree(&preg);
Expand Down

0 comments on commit 51e3360

Please sign in to comment.