Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-15-SP7:Update
python3-sqlparse
CVE-2024-4340-catch-recursionerror.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File CVE-2024-4340-catch-recursionerror.patch of Package python3-sqlparse
From b4a39d9850969b4e1d6940d32094ee0b42a2cf03 Mon Sep 17 00:00:00 2001 From: Andi Albrecht <albrecht.andi@gmail.com> Date: Sat, 13 Apr 2024 13:59:00 +0200 Subject: [PATCH] Raise SQLParseError instead of RecursionError. --- CHANGELOG | 5 +++++ sqlparse/sql.py | 14 +++++++++----- tests/test_regressions.py | 17 ++++++++++++++++- 3 files changed, 30 insertions(+), 6 deletions(-) Index: sqlparse-0.4.2/sqlparse/sql.py =================================================================== --- sqlparse-0.4.2.orig/sqlparse/sql.py +++ sqlparse-0.4.2/sqlparse/sql.py @@ -10,6 +10,7 @@ import re from sqlparse import tokens as T +from sqlparse.exceptions import SQLParseError from sqlparse.utils import imt, remove_quotes @@ -209,11 +210,14 @@ class TokenList(Token): This method is recursively called for all child tokens. """ - for token in self.tokens: - if token.is_group: - yield from token.flatten() - else: - yield token + try: + for token in self.tokens: + if token.is_group: + yield from token.flatten() + else: + yield token + except RecursionError as err: + raise SQLParseError('Maximum recursion depth exceeded') from err def get_sublists(self): for token in self.tokens: Index: sqlparse-0.4.2/tests/test_regressions.py =================================================================== --- sqlparse-0.4.2.orig/tests/test_regressions.py +++ sqlparse-0.4.2/tests/test_regressions.py @@ -1,7 +1,10 @@ +import sys + import pytest import sqlparse from sqlparse import sql, tokens as T +from sqlparse.exceptions import SQLParseError def test_issue9(): @@ -418,3 +421,16 @@ def test_splitting_at_and_backticks_issu 'grant foo to user1@`myhost`; grant bar to user1@`myhost`;') assert len(splitted) == 2 assert splitted[-1] == 'grant bar to user1@`myhost`;' + + +@pytest.fixture +def limit_recursion(): + curr_limit = sys.getrecursionlimit() + sys.setrecursionlimit(100) + yield + sys.setrecursionlimit(curr_limit) + + +def test_max_recursion(limit_recursion): + with pytest.raises(SQLParseError): + sqlparse.parse('[' * 1000 + ']' * 1000)
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor