CVE-2022-31100 (published 2022-06-27T22:15Z)

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 v2 base score: 4.0 (AV:N/AC:L/Au:S/C:N/I:N/A:P)
CVSS v3 base score: 6.5, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H)

Weakness information:
cwe_id: CWE-617
cwe_name: Reachable Assertion
description: 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.
extended_description: 
            While assertion is good for catching logic errors and reducing the chances of reaching more serious vulnerability conditions, it can still lead to a denial of service.
            For example, if a server handles multiple simultaneous connections, and an assert() occurs in one single connection that causes all other connections to be dropped, this is a reachable assertion that leads to a denial of service.
         
         

Fix information:
repo_url: https://github.com/rulex-rs/rulex
commit_details: repo_url: https://github.com/rulex-rs/rulex
author: Ludwig Stecher
author_date: 2022-06-18 22:20:58+02:00
msg: Fix panics due to slicing UTF8 strings incorrectly
repository: repo_url: https://github.com/rulex-rs/rulex
repo_name: visit repo url
description: visit repo url
repo_language: visit repo url
owner: rulex-rs
file_changes: filename: parsers.rs
change_type: ModificationType.MODIFY
diff: @@ -594,26 +594,33 @@ fn parse_quoted_text(input: &str) -> Result<Cow<'_, str>, ParseErrorKind> {
 
             loop {
                 let mut chars = s.chars();
+                let char_len;
                 match chars.next() {
-                    Some('\\') => match chars.next() {
-                        Some('\\') => {
-                            buf.push('\\');
-                            s = &s[1..];
+                    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('"') => {
-                            buf.push('"');
-                            s = &s[1..];
-                        }
-                        _ => {
-                            return Err(ParseErrorKind::InvalidEscapeInStringAt(
-                                input.len() - s.len(),
-                            ));
-                        }
-                    },
-                    Some(c) => buf.push(c),
+                    }
+                    Some(c) => {
+                        char_len = c.len_utf8();
+                        buf.push(c)
+                    }
                     None => break,
                 }
-                s = &s[1..];
+                s = &s[char_len..];
             }
             Cow::Owned(buf)
         }

programming_language: Rust
filename: tokenize.rs
change_type: ModificationType.MODIFY
diff: @@ -161,8 +161,8 @@ pub(crate) fn tokenize(mut input: &str) -> Vec<(Token, Span)> {
                                 Some(len) => (len + 4, Token::ErrorMsg(ParseErrorMsg::BackslashK)),
                                 _ => (2, Token::ErrorMsg(ParseErrorMsg::Backslash)),
                             }
-                        } else if input.len() >= 2 {
-                            (2, Token::ErrorMsg(ParseErrorMsg::Backslash))
+                        } else if let Some(next) = input.chars().nth(1) {
+                            (1 + next.len_utf8(), Token::ErrorMsg(ParseErrorMsg::Backslash))
                         } else {
                             (1, Token::Error)
                         }

programming_language: Rust
filename: 6.txt
change_type: ModificationType.ADD
diff: @@ -0,0 +1,5 @@
+# unicode strings
+
+'ä Ŧ 🤦🏼‍♂️'
+-----
+\xE4 Ŧ \x{1F926}\x{1F3FC}\x{200D}\x{2642}\x{FE0F}
\ No newline at end of file

programming_language: Haskell
filename: 7.txt
change_type: ModificationType.ADD
diff: @@ -0,0 +1,7 @@
+#! expect=error
+# this mustn't panic when tokenizing
+
+C ؾ\ ؾ \u{ؾ} U+ؾ Uؾ' ؾ'
+-----
+ERROR: Backslash escapes are not supported
+SPAN: 42..44
\ No newline at end of file

programming_language: Shell