Skip to content

Commit a822745

Browse files
committed
Allow to modify recursion limit using env variable
Users can now change the recursion limit of match in pcre_exec by exporting the OSCAP_PCRE_EXEC_RECURSION_LIMIT environemnt variable. If the variable isn't specified the default value is used. Also changes the default limit to 5000.
1 parent bc7238b commit a822745

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

docs/developer/developer.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@ behaviour.
317317

318318
* *OSCAP_FULL_VALIDATION=1* - validate all exported documents (slower)
319319
* *SEXP_VALIDATE_DISABLE=1* - do not validate SEXP expressions (faster)
320+
* *OSCAP_PCRE_EXEC_RECURSION_LIMIT* - override default recursion limit
321+
for match in pcre_exec call in textfilecontent(54) probes.
320322

321323

322324

src/common/util.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
#endif
4848

4949
#define PATH_SEPARATOR '/'
50-
#define OSCAP_PCRE_EXEC_RECURSION_LIMIT 1000
50+
#define OSCAP_PCRE_EXEC_RECURSION_LIMIT_DEFAULT 5000
5151

5252
int oscap_string_to_enum(const struct oscap_string_map *map, const char *str)
5353
{
@@ -368,7 +368,14 @@ int oscap_get_substrings(char *str, int *ofs, pcre *re, int want_substrs, char *
368368
}
369369

370370
struct pcre_extra extra;
371-
extra.match_limit_recursion = OSCAP_PCRE_EXEC_RECURSION_LIMIT;
371+
extra.match_limit_recursion = OSCAP_PCRE_EXEC_RECURSION_LIMIT_DEFAULT;
372+
char *limit_str = getenv("OSCAP_PCRE_EXEC_RECURSION_LIMIT");
373+
if (limit_str != NULL) {
374+
unsigned long limit;
375+
if (sscanf(limit_str, "%lu", &limit) == 1) {
376+
extra.match_limit_recursion = limit;
377+
}
378+
}
372379
extra.flags = PCRE_EXTRA_MATCH_LIMIT_RECURSION;
373380
#if defined(OS_SOLARIS)
374381
rc = pcre_exec(re, &extra, str, strlen(str), *ofs, PCRE_NO_UTF8_CHECK, ovector, ovector_len);

0 commit comments

Comments
 (0)