Skip to content

Commit bd71db8

Browse files
committed
Python: DataFlowPublic.qll annotations
1 parent c46c662 commit bd71db8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/**
22
* Provides Python-specific definitions for use in the data flow library.
33
*/
4+
overlay[local]
5+
module;
46

57
private import python
68
private import DataFlowPrivate
@@ -22,6 +24,7 @@ private import semmle.python.frameworks.data.ModelsAsData
2224
* - Module variable nodes: These represent global variables and act as canonical targets for reads and writes of these.
2325
* - Synthetic nodes: These handle flow in various special cases.
2426
*/
27+
overlay[local]
2528
newtype TNode =
2629
/** A node corresponding to a control flow node. */
2730
TCfgNode(ControlFlowNode node) {
@@ -157,6 +160,7 @@ private import semmle.python.internal.CachedStages
157160
* An element, viewed as a node in a data flow graph. Either an SSA variable
158161
* (`EssaNode`) or a control flow node (`CfgNode`).
159162
*/
163+
overlay[local]
160164
class Node extends TNode {
161165
/** Gets a textual representation of this element. */
162166
cached
@@ -324,6 +328,7 @@ class ScopeEntryDefinitionNode extends Node, TScopeEntryDefinitionNode {
324328
* The value of a parameter at function entry, viewed as a node in a data
325329
* flow graph.
326330
*/
331+
overlay[local]
327332
class ParameterNode extends Node instanceof ParameterNodeImpl {
328333
/** Gets the parameter corresponding to this node, if any. */
329334
final Parameter getParameter() { result = super.getParameter() }
@@ -345,6 +350,7 @@ class LocalSourceParameterNode extends ExtractedParameterNode, LocalSourceNode {
345350
ExtractedParameterNode parameterNode(Parameter p) { result.getParameter() = p }
346351

347352
/** A data flow node that represents a call argument. */
353+
overlay[global]
348354
abstract class ArgumentNode extends Node {
349355
/** Holds if this argument occurs at the given position in the given call. */
350356
abstract predicate argumentOf(DataFlowCall call, ArgumentPosition pos);
@@ -383,6 +389,7 @@ private Node implicitArgumentNode() {
383389
/**
384390
* A data flow node that represents a call argument found in the source code.
385391
*/
392+
overlay[global]
386393
class ExtractedArgumentNode extends ArgumentNode {
387394
ExtractedArgumentNode() {
388395
this = getCallArgApproximation()
@@ -469,6 +476,7 @@ class ModuleVariableNode extends Node, TModuleVariableNode {
469476
GlobalVariable getVariable() { result = var }
470477

471478
/** Gets a node that reads this variable. */
479+
overlay[global]
472480
Node getARead() {
473481
result = this.getALocalRead()
474482
or
@@ -500,10 +508,12 @@ class ModuleVariableNode extends Node, TModuleVariableNode {
500508
override Location getLocation() { result = mod.getLocation() }
501509
}
502510

511+
overlay[global]
503512
private ModuleVariableNode import_star_read(Node n) {
504513
resolved_import_star_module(result.getModule(), result.getVariable().getId(), n)
505514
}
506515

516+
overlay[global]
507517
pragma[nomagic]
508518
private predicate resolved_import_star_module(Module m, string name, Node n) {
509519
exists(NameNode nn | nn = n.asCfgNode() |
@@ -625,6 +635,7 @@ signature predicate guardChecksSig(GuardNode g, ControlFlowNode node, boolean br
625635
* This is expected to be used in `isBarrier`/`isSanitizer` definitions
626636
* in data flow and taint tracking.
627637
*/
638+
overlay[global]
628639
module BarrierGuard<guardChecksSig/3 guardChecks> {
629640
/** Gets a node that is safely guarded by the given guard check. */
630641
ExprNode getABarrierNode() {
@@ -652,6 +663,7 @@ private module WithParam<ParamSig P> {
652663
*/
653664
module ParameterizedBarrierGuard<ParamSig P, WithParam<P>::guardChecksSig/4 guardChecks> {
654665
/** Gets a node that is safely guarded by the given guard check with parameter `param`. */
666+
overlay[global]
655667
ExprNode getABarrierNode(P param) {
656668
exists(GuardNode g, EssaDefinition def, ControlFlowNode node, boolean branch |
657669
AdjacentUses::useOfDef(def, node) and
@@ -671,6 +683,7 @@ module ParameterizedBarrierGuard<ParamSig P, WithParam<P>::guardChecksSig/4 guar
671683
module ExternalBarrierGuard {
672684
private import semmle.python.ApiGraphs
673685

686+
overlay[global]
674687
private predicate guardCheck(GuardNode g, ControlFlowNode node, boolean branch, string kind) {
675688
exists(API::CallNode call, API::Node parameter |
676689
parameter = call.getAParameter() and
@@ -689,6 +702,7 @@ module ExternalBarrierGuard {
689702
*
690703
* INTERNAL: Do not use.
691704
*/
705+
overlay[global]
692706
ExprNode getAnExternalBarrierNode(string kind) {
693707
result = ParameterizedBarrierGuard<string, guardCheck/4>::getABarrierNode(kind)
694708
}
@@ -698,6 +712,7 @@ module ExternalBarrierGuard {
698712
* Algebraic datatype for tracking data content associated with values.
699713
* Content can be collection elements or object attributes.
700714
*/
715+
overlay[local]
701716
newtype TContent =
702717
/** An element of a list. */
703718
TListElementContent() or
@@ -769,6 +784,7 @@ newtype TContent =
769784
* If the value is a collection, it can have elements,
770785
* if it is an object, it can have attribute values.
771786
*/
787+
overlay[local]
772788
class Content extends TContent {
773789
/** Gets a textual representation of this element. */
774790
string toString() { result = "Content" }

0 commit comments

Comments
 (0)