Skip to content

Commit b023d73

Browse files
authored
Merge pull request github#5504 from RasmusWL/type-tracking-first-predicate-private
Python: Ensure first type-tracking predicate is private
2 parents 1473778 + 5920038 commit b023d73

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

python/ql/src/semmle/python/Concepts.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,9 @@ module Cryptography {
563563
/** Provides classes for modeling new key-pair generation APIs. */
564564
module KeyGeneration {
565565
/** Gets a back-reference to the keysize argument `arg` that was used to generate a new key-pair. */
566-
DataFlow::LocalSourceNode keysizeBacktracker(DataFlow::TypeBackTracker t, DataFlow::Node arg) {
566+
private DataFlow::LocalSourceNode keysizeBacktracker(
567+
DataFlow::TypeBackTracker t, DataFlow::Node arg
568+
) {
567569
t.start() and
568570
arg = any(KeyGeneration::Range r).getKeySizeArg() and
569571
result = arg.getALocalSource()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ private newtype TTypeTracker = MkTypeTracker(Boolean hasCall, OptionalAttributeN
180180
* It is recommended that all uses of this type are written in the following form,
181181
* for tracking some type `myType`:
182182
* ```
183-
* DataFlow::LocalSourceNode myType(DataFlow::TypeTracker t) {
183+
* private DataFlow::LocalSourceNode myType(DataFlow::TypeTracker t) {
184184
* t.start() and
185185
* result = < source of myType >
186186
* or
@@ -341,7 +341,7 @@ private newtype TTypeBackTracker = MkTypeBackTracker(Boolean hasReturn, Optional
341341
* for back-tracking some callback type `myCallback`:
342342
*
343343
* ```
344-
* DataFlow::LocalSourceNode myCallback(DataFlow::TypeBackTracker t) {
344+
* private DataFlow::LocalSourceNode myCallback(DataFlow::TypeBackTracker t) {
345345
* t.start() and
346346
* result = (< some API call >).getArgument(< n >).getALocalSource()
347347
* or

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ private module CryptographyModel {
7676
}
7777

7878
/** Gets a reference to a predefined curve class instance with a specific key size (in bits), as well as the origin of the class. */
79-
private DataFlow::Node curveClassInstanceWithKeySize(
79+
private DataFlow::LocalSourceNode curveClassInstanceWithKeySize(
8080
DataFlow::TypeTracker t, int keySize, DataFlow::Node origin
8181
) {
8282
t.start() and
83-
result.asCfgNode().(CallNode).getFunction() = curveClassWithKeySize(keySize).asCfgNode() and
83+
result.(DataFlow::CallCfgNode).getFunction() = curveClassWithKeySize(keySize) and
8484
origin = result
8585
or
8686
// Due to bad performance when using normal setup with we have inlined that code and forced a join
@@ -102,7 +102,7 @@ private module CryptographyModel {
102102

103103
/** Gets a reference to a predefined curve class instance with a specific key size (in bits), as well as the origin of the class. */
104104
DataFlow::Node curveClassInstanceWithKeySize(int keySize, DataFlow::Node origin) {
105-
result = curveClassInstanceWithKeySize(DataFlow::TypeTracker::end(), keySize, origin)
105+
curveClassInstanceWithKeySize(DataFlow::TypeTracker::end(), keySize, origin).flowsTo(result)
106106
}
107107
}
108108

python/ql/test/experimental/dataflow/typetracking/moduleattr.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import python
22
import semmle.python.dataflow.new.DataFlow
33
import semmle.python.dataflow.new.TypeTracker
44

5-
DataFlow::LocalSourceNode module_tracker(TypeTracker t) {
5+
private DataFlow::LocalSourceNode module_tracker(TypeTracker t) {
66
t.start() and
77
result = DataFlow::importNode("module")
88
or
@@ -13,7 +13,7 @@ query DataFlow::Node module_tracker() {
1313
module_tracker(DataFlow::TypeTracker::end()).flowsTo(result)
1414
}
1515

16-
DataFlow::LocalSourceNode module_attr_tracker(TypeTracker t) {
16+
private DataFlow::LocalSourceNode module_attr_tracker(TypeTracker t) {
1717
t.startInAttr("attr") and
1818
result = module_tracker()
1919
or

python/ql/test/experimental/dataflow/typetracking/tracked.ql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import TestUtilities.InlineExpectationsTest
66
// -----------------------------------------------------------------------------
77
// tracked
88
// -----------------------------------------------------------------------------
9-
DataFlow::LocalSourceNode tracked(TypeTracker t) {
9+
private DataFlow::LocalSourceNode tracked(TypeTracker t) {
1010
t.start() and
1111
result.asCfgNode() = any(NameNode n | n.getId() = "tracked")
1212
or
@@ -34,14 +34,14 @@ class TrackedTest extends InlineExpectationsTest {
3434
// -----------------------------------------------------------------------------
3535
// int + str
3636
// -----------------------------------------------------------------------------
37-
DataFlow::LocalSourceNode int_type(TypeTracker t) {
37+
private DataFlow::LocalSourceNode int_type(TypeTracker t) {
3838
t.start() and
3939
result.asCfgNode() = any(CallNode c | c.getFunction().(NameNode).getId() = "int")
4040
or
4141
exists(TypeTracker t2 | result = int_type(t2).track(t2, t))
4242
}
4343

44-
DataFlow::LocalSourceNode string_type(TypeTracker t) {
44+
private DataFlow::LocalSourceNode string_type(TypeTracker t) {
4545
t.start() and
4646
result.asCfgNode() = any(CallNode c | c.getFunction().(NameNode).getId() = "str")
4747
or
@@ -83,7 +83,7 @@ class TrackedStringTest extends InlineExpectationsTest {
8383
// -----------------------------------------------------------------------------
8484
// tracked_self
8585
// -----------------------------------------------------------------------------
86-
DataFlow::LocalSourceNode tracked_self(TypeTracker t) {
86+
private DataFlow::LocalSourceNode tracked_self(TypeTracker t) {
8787
t.start() and
8888
exists(Function f |
8989
f.isMethod() and

0 commit comments

Comments
 (0)