summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--regex.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/regex.c b/regex.c
index 3a14b25..642e357 100644
--- a/regex.c
+++ b/regex.c
@@ -123,6 +123,14 @@ bool bfs_regexec(struct bfs_regex *regex, const char *str, enum bfs_regexec_flag
const unsigned char *ustr = (const unsigned char *)str;
const unsigned char *end = ustr + len;
+ // The docs for onig_{match,search}() say
+ //
+ // Do not pass invalid byte string in the regex character encoding.
+ if (!onigenc_is_valid_mbc_string(onig_get_encoding(regex->impl), ustr, end)) {
+ *err = 0;
+ return false;
+ }
+
int ret;
if (flags & BFS_REGEX_ANCHOR) {
ret = onig_match(regex->impl, ustr, end, ustr, NULL, ONIG_OPTION_DEFAULT);