1
+ /**
2
+ * Provides classes modeling PEP 249.
3
+ * See https://www.python.org/dev/peps/pep-0249/.
4
+ */
5
+
1
6
private import python
2
7
private import experimental.dataflow.DataFlow
3
8
private import experimental.dataflow.RemoteFlowSources
4
9
private import experimental.semmle.python.Concepts
5
10
11
+ /** A module implementing PEP 249. Extend this class for implementations. */
6
12
abstract class PEP249Module extends DataFlow:: Node { }
7
13
8
14
/** Gets a reference to a connect call. */
@@ -19,7 +25,7 @@ DataFlow::Node connect() { result = connect(DataFlow::TypeTracker::end()) }
19
25
/**
20
26
* Provides models for the `db.Conection` class
21
27
*
22
- * See apiref .
28
+ * See https://www.python.org/dev/peps/pep-0249/#connection-objects .
23
29
*/
24
30
module Connection {
25
31
/**
@@ -30,6 +36,9 @@ module Connection {
30
36
* library.
31
37
*
32
38
* Use `Conection::instance()` predicate to get references to instances of `db.Conection`.
39
+ *
40
+ * Extend this class if the module implementing PEP 249 offers more direct ways to obtain
41
+ * a connection than going through `connect`.
33
42
*/
34
43
abstract class InstanceSource extends DataFlow:: Node { }
35
44
@@ -52,40 +61,49 @@ module Connection {
52
61
DataFlow:: Node instance ( ) { result = instance ( DataFlow:: TypeTracker:: end ( ) ) }
53
62
}
54
63
55
- /** Provides models for the `django.db.connection.cursor` method. */
64
+ /**
65
+ * Provides models for the `db.connection.cursor` method.
66
+ * See https://www.python.org/dev/peps/pep-0249/#cursor.
67
+ */
56
68
module cursor {
57
- /** Gets a reference to the `django. db.connection.cursor` metod. */
69
+ /** Gets a reference to the `db.connection.cursor` metod. */
58
70
private DataFlow:: Node methodRef ( DataFlow:: TypeTracker t ) {
59
71
t .startInAttr ( "cursor" ) and
60
72
result = Connection:: instance ( )
61
73
or
62
74
exists ( DataFlow:: TypeTracker t2 | result = methodRef ( t2 ) .track ( t2 , t ) )
63
75
}
64
76
65
- /** Gets a reference to the `django. db.connection.cursor` metod. */
77
+ /** Gets a reference to the `db.connection.cursor` metod. */
66
78
DataFlow:: Node methodRef ( ) { result = methodRef ( DataFlow:: TypeTracker:: end ( ) ) }
67
79
68
- /** Gets a reference to a result of calling `django. db.connection.cursor`. */
80
+ /** Gets a reference to a result of calling `db.connection.cursor`. */
69
81
private DataFlow:: Node methodResult ( DataFlow:: TypeTracker t ) {
70
82
t .start ( ) and
71
83
result .asCfgNode ( ) .( CallNode ) .getFunction ( ) = methodRef ( ) .asCfgNode ( )
72
84
or
73
85
exists ( DataFlow:: TypeTracker t2 | result = methodResult ( t2 ) .track ( t2 , t ) )
74
86
}
75
87
76
- /** Gets a reference to a result of calling `django. db.connection.cursor`. */
88
+ /** Gets a reference to a result of calling `db.connection.cursor`. */
77
89
DataFlow:: Node methodResult ( ) { result = methodResult ( DataFlow:: TypeTracker:: end ( ) ) }
78
90
}
79
91
80
- /** Gets a reference to the `django.db.connection.cursor.execute` function. */
92
+ /**
93
+ * Gets a reference to the `db.connection.cursor.execute` function.
94
+ * See https://www.python.org/dev/peps/pep-0249/#id15.
95
+ */
81
96
private DataFlow:: Node execute ( DataFlow:: TypeTracker t ) {
82
97
t .startInAttr ( "execute" ) and
83
98
result = cursor:: methodResult ( )
84
99
or
85
100
exists ( DataFlow:: TypeTracker t2 | result = execute ( t2 ) .track ( t2 , t ) )
86
101
}
87
102
88
- /** Gets a reference to the `django.db.connection.cursor.execute` function. */
103
+ /**
104
+ * Gets a reference to the `db.connection.cursor.execute` function.
105
+ * See https://www.python.org/dev/peps/pep-0249/#id15.
106
+ */
89
107
DataFlow:: Node execute ( ) { result = execute ( DataFlow:: TypeTracker:: end ( ) ) }
90
108
91
109
private class DbConnectionExecute extends SqlExecution:: Range , DataFlow:: CfgNode {
0 commit comments