diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2022-02-24 11:21:45 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2022-02-24 11:21:45 -0500 |
commit | 0633154419955e35470b38aafd49b6f52510333a (patch) | |
tree | 67788d8f14938d3073920ca4d548024903b425bf | |
parent | 81bc52baa51f7615f11338b80c98dff86c1578f7 (diff) | |
download | bfs-0633154419955e35470b38aafd49b6f52510333a.tar.xz |
regex: Test if the string is valid before matching
-rw-r--r-- | regex.c | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -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); |