Skip to content

Commit 3dc8217

Browse files
catenacybervictorjulien
authored andcommitted
fuzz: forbid usage of pcre with \X
Ticket: 8634 (cherry picked from commit 097975e)
1 parent 0dad38f commit 3dc8217

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/detect-pcre.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,21 @@ static DetectPcreData *DetectPcreParse (DetectEngineCtx *de_ctx,
641641
if (capture_names == NULL || strlen(capture_names) == 0)
642642
opts |= PCRE2_NO_AUTO_CAPTURE;
643643

644+
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
645+
// forbid use of \X Unicode extended grapheme cluster as slow
646+
bool escape = false;
647+
for (size_t i = 0; i < strlen(re); i++) {
648+
if (escape) {
649+
if (re[i] == 'X') {
650+
goto error;
651+
}
652+
escape = false;
653+
} else if (re[i] == '\\') {
654+
escape = true;
655+
}
656+
}
657+
658+
#endif
644659
pd->parse_regex.regex =
645660
pcre2_compile((PCRE2_SPTR8)re, PCRE2_ZERO_TERMINATED, opts, &en, &eo2, NULL);
646661
if (pd->parse_regex.regex == NULL && en == 115) { // reference to nonexistent subpattern

0 commit comments

Comments
 (0)