From 7648d56fc3507ef6a9001bd619d18c078f8da528 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 11 Dec 2021 09:01:03 +1100 Subject: [PATCH] Fix parsing nul bytes in regex Fixes #4460 --- src/regex_impl.cc | 2 +- test/regression/4460-nul-byte-in-regex/cmd | 1 + test/regression/4460-nul-byte-in-regex/in | Bin 0 -> 3 bytes test/regression/4460-nul-byte-in-regex/out | 1 + 4 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 test/regression/4460-nul-byte-in-regex/cmd create mode 100644 test/regression/4460-nul-byte-in-regex/in create mode 100644 test/regression/4460-nul-byte-in-regex/out diff --git a/src/regex_impl.cc b/src/regex_impl.cc index 2161d113..3dc8bd6b 100644 --- a/src/regex_impl.cc +++ b/src/regex_impl.cc @@ -340,7 +340,7 @@ private: case '|': case ')': return {}; default: - if (contains("^$.*+?[]{}", cp) or (cp >= 0xF0000 and cp <= 0xFFFFF)) + if (contains(StringView{"^$.*+?[]{}"}, cp) or (cp >= 0xF0000 and cp <= 0xFFFFF)) parse_error(format("unexpected '{}'", cp)); ++m_pos; return add_node(ParsedRegex::Literal, cp); diff --git a/test/regression/4460-nul-byte-in-regex/cmd b/test/regression/4460-nul-byte-in-regex/cmd new file mode 100644 index 00000000..660eddfb --- /dev/null +++ b/test/regression/4460-nul-byte-in-regex/cmd @@ -0,0 +1 @@ +*%sd diff --git a/test/regression/4460-nul-byte-in-regex/in b/test/regression/4460-nul-byte-in-regex/in new file mode 100644 index 0000000000000000000000000000000000000000..bd474b2519cc15eab801ff851cc7d50f0dee49a1 GIT binary patch literal 3 KcmZQz-~s>u4FC%O literal 0 HcmV?d00001 diff --git a/test/regression/4460-nul-byte-in-regex/out b/test/regression/4460-nul-byte-in-regex/out new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/test/regression/4460-nul-byte-in-regex/out @@ -0,0 +1 @@ +