CVE-2022-31100 (Rust, published 2022-06-27T22:15Z)
Description: value: rulex is a new, portable, regular expression language. When parsing untrusted rulex expressions, rulex may crash, possibly enabling a Denial of Service attack. This happens when the expression contains a multi-byte UTF-8 code point in a string literal or after a backslash, because rulex tries to slice into the code point and panics as a result. This is a security concern for you, if your service parses untrusted rulex expressions (expressions provided by an untrusted user), and your service becomes unavailable when the thread running rulex panics. The crashes are fixed in version **0.4.3**. Affected users are advised to update to this version. The only known workaround for this issue is to assume that regular expression parsing will panic and to add logic to catch panics.
Severity: MEDIUM (CVSS v3 base score: 6.5)
Weakness: CWE-617 \u2014 Reachable Assertion
The product contains an assert() or similar statement that can be triggered by an attacker, which leads to an application exit or other behavior that is more severe than necessary.
Repository: https://github.com/rulex-rs/rulex
Files changed:
rulex-lib/src/parse/parsers.rs
rulex-lib/src/parse/tokenize.rs
rulex-lib/tests/testcases/basics/6.txt
rulex-lib/tests/testcases/basics/7.txt
Commit message: Fix panics due to slicing UTF8 strings incorrectly


Vulnerable code:
                    Some('\\') => match chars.next() {
                        Some('\\') => {
                            buf.push('\\');
                            s = &s[1..];
                        Some('"') => {
                            buf.push('"');
                            s = &s[1..];
                        }
                        _ => {
                            return Err(ParseErrorKind::InvalidEscapeInStringAt(
                                input.len() - s.len(),
                            ));
                        }
                    },
                    Some(c) => buf.push(c),
                s = &s[1..];
                        } else if input.len() >= 2 {
                            (2, Token::ErrorMsg(ParseErrorMsg::Backslash))

Fixed code:
                let char_len;
                    Some('\\') => {
                        char_len = 1;
                        match chars.next() {
                            Some('\\') => {
                                buf.push('\\');
                                s = &s[1..];
                            }
                            Some('"') => {
                                buf.push('"');
                                s = &s[1..];
                            }
                            _ => {
                                return Err(ParseErrorKind::InvalidEscapeInStringAt(
                                    input.len() - s.len(),
                                ));
                            }
                    }
                    Some(c) => {
                        char_len = c.len_utf8();
                        buf.push(c)
                    }
                s = &s[char_len..];
                        } else if let Some(next) = input.chars().nth(1) {
                            (1 + next.len_utf8(), Token::ErrorMsg(ParseErrorMsg::Backslash))
# unicode strings

'ä Ŧ 🤦🏼‍♂️'
-----
\xE4 Ŧ \x{1F926}\x{1F3FC}\x{200D}\x{2642}\x{FE0F}
#! expect=error
# this mustn't panic when tokenizing

C ؾ\ ؾ \u{ؾ} U+ؾ Uؾ' ؾ'
-----
ERROR: Backslash escapes are not supported
SPAN: 42..44