From: Soumya Sambu <[email protected]>

Passing a heavily nested list to sqlparse.parse() leads to a Denial
of Service due to RecursionError.

Reference:
https://nvd.nist.gov/vuln/detail/CVE-2024-4340

Upstream-patch:
https://github.com/andialbrecht/sqlparse/commit/b4a39d9850969b4e1d6940d32094ee0b42a2cf03

Signed-off-by: Soumya Sambu <[email protected]>
---
 .../python3-sqlparse/CVE-2024-4340.patch      | 48 +++++++++++++++++++
 .../python/python3-sqlparse_0.4.2.bb          |  1 +
 2 files changed, 49 insertions(+)
 create mode 100644 
meta-python/recipes-devtools/python/python3-sqlparse/CVE-2024-4340.patch

diff --git 
a/meta-python/recipes-devtools/python/python3-sqlparse/CVE-2024-4340.patch 
b/meta-python/recipes-devtools/python/python3-sqlparse/CVE-2024-4340.patch
new file mode 100644
index 0000000000..8d45a27dd9
--- /dev/null
+++ b/meta-python/recipes-devtools/python/python3-sqlparse/CVE-2024-4340.patch
@@ -0,0 +1,48 @@
+From b4a39d9850969b4e1d6940d32094ee0b42a2cf03 Mon Sep 17 00:00:00 2001
+From: Andi Albrecht <[email protected]>
+Date: Sat, 13 Apr 2024 13:59:00 +0200
+Subject: [PATCH] Raise SQLParseError instead of RecursionError.
+
+CVE: CVE-2024-4340
+
+Upstream-Status: Backport 
[https://github.com/andialbrecht/sqlparse/commit/b4a39d9850969b4e1d6940d32094ee0b42a2cf03]
+
+Signed-off-by: Soumya Sambu <[email protected]>
+---
+ sqlparse/sql.py | 14 +++++++++-----
+ 1 file changed, 9 insertions(+), 5 deletions(-)
+
+diff --git a/sqlparse/sql.py b/sqlparse/sql.py
+index 6a32c26..ffffc77 100644
+--- a/sqlparse/sql.py
++++ b/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:
+--
+2.40.0
diff --git a/meta-python/recipes-devtools/python/python3-sqlparse_0.4.2.bb 
b/meta-python/recipes-devtools/python/python3-sqlparse_0.4.2.bb
index b5cc41e730..80f37b1368 100644
--- a/meta-python/recipes-devtools/python/python3-sqlparse_0.4.2.bb
+++ b/meta-python/recipes-devtools/python/python3-sqlparse_0.4.2.bb
@@ -7,6 +7,7 @@ LIC_FILES_CHKSUM = 
"file://LICENSE;md5=2b136f573f5386001ea3b7b9016222fc"
 SRC_URI += "file://0001-sqlparse-change-shebang-to-python3.patch \
             file://run-ptest \
             file://CVE-2023-30608.patch \
+            file://CVE-2024-4340.patch \
            "
 
 SRC_URI[sha256sum] = 
"0c00730c74263a94e5a9919ade150dfc3b19c574389985446148402998287dae"
-- 
2.40.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#114959): 
https://lists.openembedded.org/g/openembedded-devel/message/114959
Mute This Topic: https://lists.openembedded.org/mt/110710209/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-devel/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to