File: 01-escape_non_expressions.patch

package info (click to toggle)
python-sql 1.4.0-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 436 kB
  • sloc: python: 3,956; sh: 9; makefile: 7
file content (32 lines) | stat: -rw-r--r-- 1,084 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Description: Escape non expressions for unary operators
 This patch fixes the vulnerability for SQL injection attacks
 from
 https://discuss.tryton.org/t/security-release-for-issue-93
Author: Cédric Krier <cedric.krier@b2ck.com>
Bug: https://bugs.tryton.org/python-sql/93

--- a/sql/operators.py
+++ b/sql/operators.py
@@ -121,7 +121,8 @@
         return self
 
     def __str__(self):
-        return '(' + (' %s ' % self._operator).join(map(str, self)) + ')'
+        return '(' + (' %s ' % self._operator).join(
+            map(self._format, self)) + ')'
 
 
 class And(NaryOperator):
--- a/sql/tests/test_operators.py
+++ b/sql/tests/test_operators.py
@@ -25,6 +25,10 @@
         self.assertEqual(str(and_), '(%s AND "c2")')
         self.assertEqual(and_.params, (True,))
 
+        and_ = And((Literal(True), 'foo'))
+        self.assertEqual(str(and_), '(%s AND %s)')
+        self.assertEqual(and_.params, (True, 'foo'))
+
     def test_operator_operators(self):
         and_ = And((Literal(True), self.table.c1))
         and2 = and_ & And((Literal(True), self.table.c2))