Skip to content

Commit c457abd

Browse files
committed
Remove unnecessary parts in regex for bad escaping.
The regex tried to deal with situations where escaping in the SQL to be parsed was suspicious.
1 parent b949fdf commit c457abd

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

CHANGELOG

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
Development Version
22
-------------------
33

4+
Notable Changes
5+
6+
* IMPORTANT: This release fixes a security vulnerability in the
7+
parser where a regular expression vulnerable to ReDOS (Regular
8+
Expression Denial of Service) was used. See the security advisory
9+
for details: https://github.com/andialbrecht/sqlparse/security/advisories/GHSA-rrm6-wvj7-cwh2
10+
The vulnerability was discovered by @erik-krogh from GitHub
11+
Security Lab (GHSL). Thanks for reporting!
12+
413
Bug Fixes
514

615
* Revert a change from 0.4.0 that changed IN to be a comparison (issue694).
716
The primary expectation is that IN is treated as a keyword and not as a
817
comparison operator. That also follows the definition of reserved keywords
918
for the major SQL syntax definitions.
19+
* Fix regular expressions for string parsing.
1020

1121
Other
1222

sqlparse/keywords.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@
5959
(r'(?![_A-ZÀ-Ü])-?(\d+(\.\d*)|\.\d+)(?![_A-ZÀ-Ü])',
6060
tokens.Number.Float),
6161
(r'(?![_A-ZÀ-Ü])-?\d+(?![_A-ZÀ-Ü])', tokens.Number.Integer),
62-
(r"'(''|\\\\|\\'|[^'])*'", tokens.String.Single),
62+
(r"'(''|\\'|[^'])*'", tokens.String.Single),
6363
# not a real string literal in ANSI SQL:
64-
(r'"(""|\\\\|\\"|[^"])*"', tokens.String.Symbol),
64+
(r'"(""|\\"|[^"])*"', tokens.String.Symbol),
6565
(r'(""|".*?[^\\]")', tokens.String.Symbol),
6666
# sqlite names can be escaped with [square brackets]. left bracket
6767
# cannot be preceded by word character or a right bracket --

tests/test_split.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def test_split_semicolon():
1818

1919

2020
def test_split_backslash():
21-
stmts = sqlparse.parse(r"select '\\'; select '\''; select '\\\'';")
22-
assert len(stmts) == 3
21+
stmts = sqlparse.parse("select '\'; select '\'';")
22+
assert len(stmts) == 2
2323

2424

2525
@pytest.mark.parametrize('fn', ['function.sql',

0 commit comments

Comments
 (0)