Skip to content

Commit 180373c

Browse files
authored
Merge pull request #4597 from yoff/python-fix-ql-doc
Python: Fix ql doc
2 parents 22b4df0 + 1023b23 commit 180373c

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

python/ql/src/semmle/python/dataflow/new/RemoteFlowSources.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Provides an extension point for for modeling user-controlled data.
3+
* Such data is often used as data-flow sources in security queries.
4+
*/
5+
16
private import python
27
private import semmle.python.dataflow.new.DataFlow
38
// Need to import since frameworks can extend `RemoteFlowSource::Range`

python/ql/src/semmle/python/dataflow/new/TypeTracker.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,24 @@ class StepSummary extends TStepSummary {
4444
}
4545
}
4646

47+
/** Provides predicates for updating step summaries (`StepSummary`s). */
4748
module StepSummary {
49+
/**
50+
* Gets the summary that corresponds to having taken a forwards
51+
* heap and/or inter-procedural step from `nodeFrom` to `nodeTo`.
52+
*/
4853
cached
4954
predicate step(Node nodeFrom, Node nodeTo, StepSummary summary) {
5055
exists(Node mid | typePreservingStep*(nodeFrom, mid) and smallstep(mid, nodeTo, summary))
5156
}
5257

58+
/**
59+
* Gets the summary that corresponds to having taken a forwards
60+
* local, heap and/or inter-procedural step from `nodeFrom` to `nodeTo`.
61+
*
62+
* Unlike `StepSummary::step`, this predicate does not compress
63+
* type-preserving steps.
64+
*/
5365
predicate smallstep(Node nodeFrom, Node nodeTo, StepSummary summary) {
5466
typePreservingStep(nodeFrom, nodeTo) and
5567
summary = LevelStep()
@@ -291,6 +303,7 @@ class TypeTracker extends TTypeTracker {
291303
}
292304
}
293305

306+
/** Provides predicates for implementing custom `TypeTracker`s. */
294307
module TypeTracker {
295308
/**
296309
* Gets a valid end point of type tracking.

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,13 @@ class Node extends TNode {
118118
Node track(TypeTracker t2, TypeTracker t) { t = t2.step(this, result) }
119119
}
120120

121+
/** A data-flow node corresponding to an SSA variable. */
121122
class EssaNode extends Node, TEssaNode {
122123
EssaVariable var;
123124

124125
EssaNode() { this = TEssaNode(var) }
125126

127+
/** Gets the `EssaVariable` represented by this data-flow node. */
126128
EssaVariable getVar() { result = var }
127129

128130
override EssaVariable asVar() { result = var }
@@ -135,11 +137,13 @@ class EssaNode extends Node, TEssaNode {
135137
override Location getLocation() { result = var.getDefinition().getLocation() }
136138
}
137139

140+
/** A data-flow node corresponding to a control-flow node. */
138141
class CfgNode extends Node, TCfgNode {
139142
ControlFlowNode node;
140143

141144
CfgNode() { this = TCfgNode(node) }
142145

146+
/** Gets the `ControlFlowNode` represented by this data-flow node. */
143147
ControlFlowNode getNode() { result = node }
144148

145149
override ControlFlowNode asCfgNode() { result = node }
@@ -352,39 +356,48 @@ class BarrierGuard extends GuardNode {
352356
}
353357

354358
/**
355-
* A reference contained in an object. This is either a field or a property.
359+
* Algebraic datatype for tracking data content associated with values.
360+
* Content can be collection elements or object attributes.
356361
*/
357362
newtype TContent =
358363
/** An element of a list. */
359364
TListElementContent() or
360365
/** An element of a set. */
361366
TSetElementContent() or
362-
/** An element of a tuple at a specifik index. */
367+
/** An element of a tuple at a specific index. */
363368
TTupleElementContent(int index) { exists(any(TupleNode tn).getElement(index)) } or
364369
/** An element of a dictionary under a specific key. */
365370
TDictionaryElementContent(string key) {
366371
key = any(KeyValuePair kvp).getKey().(StrConst).getS()
367372
or
368373
key = any(Keyword kw).getArg()
369374
} or
370-
/** An element of a dictionary at any key. */
375+
/** An element of a dictionary under any key. */
371376
TDictionaryElementAnyContent() or
372377
/** An object attribute. */
373378
TAttributeContent(string attr) { attr = any(Attribute a).getName() }
374379

380+
/**
381+
* A data-flow value can have associated content.
382+
* If the value is a collection, it can have elements,
383+
* if it is an object, it can have attribute values.
384+
*/
375385
class Content extends TContent {
376386
/** Gets a textual representation of this element. */
377387
string toString() { result = "Content" }
378388
}
379389

390+
/** An element of a list. */
380391
class ListElementContent extends TListElementContent, Content {
381392
override string toString() { result = "List element" }
382393
}
383394

395+
/** An element of a set. */
384396
class SetElementContent extends TSetElementContent, Content {
385397
override string toString() { result = "Set element" }
386398
}
387399

400+
/** An element of a tuple at a specific index. */
388401
class TupleElementContent extends TTupleElementContent, Content {
389402
int index;
390403

@@ -396,6 +409,7 @@ class TupleElementContent extends TTupleElementContent, Content {
396409
override string toString() { result = "Tuple element at index " + index.toString() }
397410
}
398411

412+
/** An element of a dictionary under a specific key. */
399413
class DictionaryElementContent extends TDictionaryElementContent, Content {
400414
string key;
401415

@@ -407,10 +421,12 @@ class DictionaryElementContent extends TDictionaryElementContent, Content {
407421
override string toString() { result = "Dictionary element at key " + key }
408422
}
409423

424+
/** An element of a dictionary under any key. */
410425
class DictionaryElementAnyContent extends TDictionaryElementAnyContent, Content {
411426
override string toString() { result = "Any dictionary element" }
412427
}
413428

429+
/** An object attribute. */
414430
class AttributeContent extends TAttributeContent, Content {
415431
private string attr;
416432

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module MySQLdb {
3232
/** Gets a reference to the `MySQLdb` module. */
3333
DataFlow::Node moduleMySQLdb() { result = moduleMySQLdb(DataFlow::TypeTracker::end()) }
3434

35+
/** MySQLdb implements PEP 249, providing ways to execute SQL statements against a database. */
3536
class MySQLdb extends PEP249Module {
3637
MySQLdb() { this = moduleMySQLdb() }
3738
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ private import python
66
private import semmle.python.dataflow.new.DataFlow
77
private import semmle.python.dataflow.new.TaintTracking
88

9+
/**
10+
* Provides models for the `Werkzeug` PyPI package.
11+
* See
12+
* - https://pypi.org/project/Werkzeug/
13+
* - https://werkzeug.palletsprojects.com/en/1.0.x/#werkzeug
14+
*/
915
module Werkzeug {
1016
/** Provides models for the `werkzeug` module. */
1117
module werkzeug {

0 commit comments

Comments
 (0)