Skip to content

Commit

Permalink
Issue 5012 - Migrate pcre to pcre2 - remove match limit
Browse files Browse the repository at this point in the history
Description: During the migration a match limit was incorrectly
             applied when in was not actually needed.  This broke
             regexes where the source target matched more than 30
             characters.

relates: #5012

Reviewed by: firstyear & spichugi(Thanks!)
  • Loading branch information
mreynolds389 committed Aug 31, 2022
1 parent 3439c24 commit a310799
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
12 changes: 10 additions & 2 deletions ldap/servers/slapd/back-ldbm/ldbm_search.c
Original file line number Diff line number Diff line change
Expand Up @@ -1941,10 +1941,18 @@ delete_search_result_set(Slapi_PBlock *pb, back_search_result_set **sr)
rc = slapi_filter_apply((*sr)->sr_norm_filter, ldbm_search_free_compiled_filter,
NULL, &filt_errs);
if (rc != SLAPI_FILTER_SCAN_NOMORE) {
slapi_log_err(SLAPI_LOG_ERR,
"delete_search_result_set", "Could not free the pre-compiled regexes in the search filter - error %d %d\n",
slapi_log_err(SLAPI_LOG_ERR, "delete_search_result_set",
"Could not free the pre-compiled regexes in the search filter - error %d %d\n",
rc, filt_errs);
}

rc = slapi_filter_apply((*sr)->sr_norm_filter_intent, ldbm_search_free_compiled_filter, NULL, &filt_errs);
if (rc != SLAPI_FILTER_SCAN_NOMORE) {
slapi_log_err(SLAPI_LOG_ERR, "delete_search_result_set",
"Could not free the pre-compiled regexes in the intent search filter - error %d %d\n",
rc, filt_errs);
}

slapi_filter_free((*sr)->sr_norm_filter, 1);
slapi_filter_free((*sr)->sr_norm_filter_intent, 1);
memset(*sr, 0, sizeof(back_search_result_set));
Expand Down
18 changes: 2 additions & 16 deletions ldap/servers/slapd/regex.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ struct slapi_regex_handle
{
pcre2_code *re_pcre;
pcre2_match_data *match_data; /* Contains the output vector */
pcre2_match_context *mcontext; /* Stores the max element limit */
};

/**
Expand Down Expand Up @@ -88,19 +87,13 @@ slapi_re_exec(Slapi_Regex *re_handle, const char *subject, time_t time_up)
}
re_handle->match_data = pcre2_match_data_create_from_pattern(re_handle->re_pcre, NULL);

if (re_handle->mcontext == NULL) {
re_handle->mcontext = pcre2_match_context_create(NULL);
pcre2_set_match_limit(re_handle->mcontext, OVEC_MATCH_LIMIT);
}


rc = pcre2_match(re_handle->re_pcre, /* the compiled pattern */
(PCRE2_SPTR)subject, /* the subject string */
strlen(subject), /* the length of the subject */
0, /* start at offset 0 in the subject */
0, /* default options */
re_handle->match_data, /* contains the resulting output vector */
re_handle->mcontext); /* stores the max element limit */
NULL); /* stores the match context */

if (rc >= 0) {
return 1; /* matched */
Expand Down Expand Up @@ -138,17 +131,13 @@ slapi_re_exec_nt(Slapi_Regex *re_handle, const char *subject)
}
re_handle->match_data = pcre2_match_data_create_from_pattern(re_handle->re_pcre, NULL);

if (re_handle->mcontext == NULL) {
re_handle->mcontext = pcre2_match_context_create(NULL);
pcre2_set_match_limit(re_handle->mcontext, OVEC_MATCH_LIMIT);
}
rc = pcre2_match(re_handle->re_pcre, /* the compiled pattern */
(PCRE2_SPTR)subject, /* the subject string */
strlen(subject), /* the length of the subject */
0, /* start at offset 0 in the subject */
0, /* default options */
re_handle->match_data, /* contains the resulting output vector */
re_handle->mcontext); /* stores the max element limit */
NULL); /* stores the match context */

if (rc >= 0) {
return 1; /* matched */
Expand Down Expand Up @@ -256,9 +245,6 @@ slapi_re_free(Slapi_Regex *re_handle)
if (re_handle->match_data) {
pcre2_match_data_free(re_handle->match_data);
}
if (re_handle->mcontext) {
pcre2_match_context_free(re_handle->mcontext);
}
slapi_ch_free((void **)&re_handle);
}
}

0 comments on commit a310799

Please sign in to comment.