Skip to content

Commit 31bd701

Browse files
authored
Python: Final LocalSourceNode fixes
1 parent 897105d commit 31bd701

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

python/ql/src/semmle/python/frameworks/PEP249.qll

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ module Connection {
5454
}
5555

5656
/** Gets a reference to an instance of `db.Connection`. */
57-
private DataFlow::Node instance(DataFlow::TypeTracker t) {
57+
private DataFlow::LocalSourceNode instance(DataFlow::TypeTracker t) {
5858
t.start() and
5959
result instanceof InstanceSource
6060
or
6161
exists(DataFlow::TypeTracker t2 | result = instance(t2).track(t2, t))
6262
}
6363

6464
/** Gets a reference to an instance of `db.Connection`. */
65-
DataFlow::Node instance() { result = instance(DataFlow::TypeTracker::end()) }
65+
DataFlow::Node instance() { instance(DataFlow::TypeTracker::end()).flowsTo(result) }
6666
}
6767

6868
/**
@@ -71,26 +71,26 @@ module Connection {
7171
*/
7272
module cursor {
7373
/** Gets a reference to the `cursor` method on a connection. */
74-
private DataFlow::Node methodRef(DataFlow::TypeTracker t) {
74+
private DataFlow::LocalSourceNode methodRef(DataFlow::TypeTracker t) {
7575
t.startInAttr("cursor") and
7676
result = Connection::instance()
7777
or
7878
exists(DataFlow::TypeTracker t2 | result = methodRef(t2).track(t2, t))
7979
}
8080

8181
/** Gets a reference to the `cursor` method on a connection. */
82-
DataFlow::Node methodRef() { result = methodRef(DataFlow::TypeTracker::end()) }
82+
DataFlow::Node methodRef() { methodRef(DataFlow::TypeTracker::end()).flowsTo(result) }
8383

8484
/** Gets a reference to a result of calling the `cursor` method on a connection. */
85-
private DataFlow::Node methodResult(DataFlow::TypeTracker t) {
85+
private DataFlow::LocalSourceNode methodResult(DataFlow::TypeTracker t) {
8686
t.start() and
8787
result.asCfgNode().(CallNode).getFunction() = methodRef().asCfgNode()
8888
or
8989
exists(DataFlow::TypeTracker t2 | result = methodResult(t2).track(t2, t))
9090
}
9191

9292
/** Gets a reference to a result of calling the `cursor` method on a connection. */
93-
DataFlow::Node methodResult() { result = methodResult(DataFlow::TypeTracker::end()) }
93+
DataFlow::Node methodResult() { methodResult(DataFlow::TypeTracker::end()).flowsTo(result) }
9494
}
9595

9696
/**
@@ -101,7 +101,7 @@ module cursor {
101101
*
102102
* See https://www.python.org/dev/peps/pep-0249/#id15.
103103
*/
104-
private DataFlow::Node execute(DataFlow::TypeTracker t) {
104+
private DataFlow::LocalSourceNode execute(DataFlow::TypeTracker t) {
105105
t.startInAttr("execute") and
106106
result in [cursor::methodResult(), Connection::instance()]
107107
or
@@ -116,7 +116,7 @@ private DataFlow::Node execute(DataFlow::TypeTracker t) {
116116
*
117117
* See https://www.python.org/dev/peps/pep-0249/#id15.
118118
*/
119-
DataFlow::Node execute() { result = execute(DataFlow::TypeTracker::end()) }
119+
DataFlow::Node execute() { execute(DataFlow::TypeTracker::end()).flowsTo(result) }
120120

121121
/** A call to the `execute` method on a cursor (or on a connection). */
122122
private class ExecuteCall extends SqlExecution::Range, DataFlow::CallCfgNode {

python/ql/test/library-tests/frameworks/modeling-example/SharedCode.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ private import semmle.python.dataflow.new.TaintTracking
66
/** A data-flow Node representing an instance of MyClass. */
77
abstract class MyClass extends DataFlow::Node { }
88

9-
private DataFlow::Node myClassGetValue(MyClass qualifier, DataFlow::TypeTracker t) {
9+
private DataFlow::LocalSourceNode myClassGetValue(MyClass qualifier, DataFlow::TypeTracker t) {
1010
t.startInAttr("get_value") and
1111
result = qualifier
1212
or
1313
exists(DataFlow::TypeTracker t2 | result = myClassGetValue(qualifier, t2).track(t2, t))
1414
}
1515

1616
DataFlow::Node myClassGetValue(MyClass qualifier) {
17-
result = myClassGetValue(qualifier, DataFlow::TypeTracker::end())
17+
myClassGetValue(qualifier, DataFlow::TypeTracker::end()).flowsTo(result)
1818
}
1919

2020
// Config

0 commit comments

Comments
 (0)