Skip to content

Commit df0f2f8

Browse files
committed
Python: Simple dataflow annotations
None of these required any changes to the dataflow libraries, so it seemed easiest to put them in their own commit.
1 parent 51ebec9 commit df0f2f8

File tree

17 files changed

+39
-0
lines changed

17 files changed

+39
-0
lines changed

python/ql/lib/semmle/python/ApiGraphs.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ module API {
451451
* allowing this predicate to be used in a negative
452452
* context when constructing new nodes.
453453
*/
454+
overlay[local]
454455
predicate moduleImportExists(string m) {
455456
Impl::isImported(m) and
456457
// restrict `moduleImport` so it will never give results for a dotted name. Note
@@ -695,6 +696,7 @@ module API {
695696
*
696697
* This is determined syntactically.
697698
*/
699+
overlay[local]
698700
cached
699701
predicate isImported(string name) {
700702
// Ignore the following module name for Python 2, as we alias `__builtin__` to `builtins` elsewhere

python/ql/lib/semmle/python/dataflow/new/FlowSummary.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ deprecated module SummaryComponentStack = Impl::Private::SummaryComponentStack;
2525
class Provenance = Impl::Public::Provenance;
2626

2727
/** Provides the `Range` class used to define the extent of `SummarizedCallable`. */
28+
overlay[local]
2829
module SummarizedCallable {
2930
/** A callable with a flow summary, identified by a unique string. */
3031
abstract class Range extends LibraryCallable, Impl::Public::SummarizedCallable {

python/ql/lib/semmle/python/dataflow/new/internal/Attributes.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/** This module provides an API for attribute reads and writes. */
2+
overlay[local]
3+
module;
24

35
private import python
46
import DataFlowUtil

python/ql/lib/semmle/python/dataflow/new/internal/Builtins.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/** Provides predicates for reasoning about built-ins in Python. */
2+
overlay[local]
3+
module;
24

35
private import python
46
private import semmle.python.dataflow.new.DataFlow

python/ql/lib/semmle/python/dataflow/new/internal/FlowSummaryImpl.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/**
22
* Provides classes and predicates for defining flow summaries.
33
*/
4+
overlay[local]
5+
module;
46

57
private import python
68
private import codeql.dataflow.internal.FlowSummaryImpl
@@ -99,6 +101,7 @@ module Input implements InputSig<Location, DataFlowImplSpecific::PythonDataFlow>
99101
private import Make<Location, DataFlowImplSpecific::PythonDataFlow, Input> as Impl
100102

101103
private module StepsInput implements Impl::Private::StepsInputSig {
104+
overlay[global]
102105
DataFlowCall getACall(Public::SummarizedCallable sc) {
103106
result =
104107
TPotentialLibraryCall([

python/ql/lib/semmle/python/dataflow/new/internal/ImportStar.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/** Provides predicates for reasoning about uses of `import *` in Python. */
2+
overlay[local]
3+
module;
24

35
private import python
46
private import semmle.python.dataflow.new.internal.Builtins
@@ -11,6 +13,7 @@ module ImportStar {
1113
* Holds if `n` is an access of a variable called `name` (which is _not_ the name of a
1214
* built-in, and which is _not_ a global defined in the enclosing module) inside the scope `s`.
1315
*/
16+
overlay[local]
1417
cached
1518
predicate namePossiblyDefinedInImportStar(NameNode n, string name, Scope s) {
1619
n.isLoad() and
@@ -61,6 +64,7 @@ module ImportStar {
6164
* Holds if `n` may refer to a global variable of the same name in the module `m`, accessible
6265
* from the scope of `n` by a chain of `import *` imports.
6366
*/
67+
overlay[global]
6468
cached
6569
predicate importStarResolvesTo(NameNode n, Module m) {
6670
m = getStarImported+(n.getEnclosingModule()) and
@@ -71,6 +75,7 @@ module ImportStar {
7175
/**
7276
* Gets a module that is imported from `m` via `import *`.
7377
*/
78+
overlay[global]
7479
cached
7580
Module getStarImported(Module m) {
7681
exists(ImportStar i, DataFlow::CfgNode imported_module |
@@ -92,6 +97,7 @@ module ImportStar {
9297
*
9398
* this would return the data-flow nodes corresponding to `foo.bar` and `quux`.
9499
*/
100+
overlay[local]
95101
cached
96102
ControlFlowNode potentialImportStarBase(Scope s) {
97103
result = any(ImportStarNode n | n.getScope() = s).getModule()

python/ql/lib/semmle/python/dataflow/new/internal/IterableUnpacking.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@
166166
*
167167
* `c`: [ListElementContent]
168168
*/
169+
overlay[local]
170+
module;
169171

170172
private import python
171173
private import DataFlowPublic

python/ql/lib/semmle/python/dataflow/new/internal/MatchUnpacking.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
* keyword arguments using the `__match_args__` attribute on the class. We do not
5151
* currently model this.
5252
*/
53+
overlay[local]
54+
module;
5355

5456
private import python
5557
private import DataFlowPublic

python/ql/lib/semmle/python/dataflow/new/internal/VariableCapture.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/** Provides logic related to captured variables. */
2+
overlay[local]
3+
module;
24

35
private import python
46
private import DataFlowPublic

python/ql/lib/semmle/python/frameworks/Flask.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* Provides classes modeling security-relevant aspects of the `flask` PyPI package.
33
* See https://flask.palletsprojects.com/en/1.1.x/.
44
*/
5+
overlay[local?]
6+
module;
57

68
private import python
79
private import semmle.python.dataflow.new.DataFlow

0 commit comments

Comments
 (0)