-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14848 from hvitved/python/shared-type-tracking
Python: Adopt shared type tracking library
- Loading branch information
Showing
24 changed files
with
503 additions
and
731 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
python/ql/lib/change-notes/2023-11-21-new-type-tracking-lib.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
category: minorAnalysis | ||
--- | ||
* Python now makes use of the shared type tracking library, exposed as `semmle.python.dataflow.new.TypeTracking`. The existing type tracking library, `semmle.python.dataflow.new.TypeTracker`, has consequently been deprecated. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* Provides classes and predicates for simple data-flow reachability suitable | ||
* for tracking types. | ||
*/ | ||
|
||
private import internal.TypeTrackingImpl as Impl | ||
import Impl::Shared::TypeTracking<Impl::TypeTrackingInput> | ||
|
||
/** A string that may appear as the name of an attribute or access path. */ | ||
class AttributeName = Impl::TypeTrackingInput::Content; | ||
|
||
/** | ||
* A summary of the steps needed to track a value to a given dataflow node. | ||
* | ||
* This can be used to track objects that implement a certain API in order to | ||
* recognize calls to that API. Note that type-tracking does not by itself provide a | ||
* source/sink relation, that is, it may determine that a node has a given type, | ||
* but it won't determine where that type came from. | ||
* | ||
* It is recommended that all uses of this type are written in the following form, | ||
* for tracking some type `myType`: | ||
* ```ql | ||
* Node myType(TypeTracker tt) { | ||
* tt.start() and | ||
* result = < source of myType > | ||
* or | ||
* exists(TypeTracker tt2 | | ||
* tt = tt2.step(myType(tt2), result) | ||
* ) | ||
* } | ||
* | ||
* Node myType() { myType(TypeTracker::end()).flowsTo(result) } | ||
* ``` | ||
* | ||
* If you want to track individual intra-procedural steps, use `tt2.smallstep` | ||
* instead of `tt2.step`. | ||
*/ | ||
class TypeTracker extends Impl::TypeTracker { | ||
/** | ||
* Holds if this is the starting point of type tracking, and the value starts in the attribute named `attrName`. | ||
* The type tracking only ends after the attribute has been loaded. | ||
*/ | ||
predicate startInAttr(string attrName) { this.startInContent(attrName) } | ||
|
||
/** | ||
* INTERNAL. DO NOT USE. | ||
* | ||
* Gets the attribute associated with this type tracker. | ||
*/ | ||
string getAttr() { | ||
result = this.getContent().asSome() | ||
or | ||
this.getContent().isNone() and | ||
result = "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.