-
Notifications
You must be signed in to change notification settings - Fork 2k
Python: Add small api enhancements determined useful during documentation work #5398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4d856d4
Python: Add small api enhancements
yoff 63b732c
Apply suggestions from code review
yoff 8f46700
Python: More review suggestions
yoff b3ff3f7
PythonÆ adjust test expectations
yoff a9af135
Python: Remove `getALocalTaintSource`
yoff c777f1d
Merge branch 'main' of github.com:github/codeql into python-api-enhan…
yoff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,3 @@ | ||
| lgtm,codescanning | ||
| * The class ParameterNode now extends LocalSourceNode, thus making methods like flowsTo available. | ||
| * The new predicate `parameterNode` can now be used to map from a `Parameter` to a data-flow node. | ||
This file contains hidden or 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
113 changes: 113 additions & 0 deletions
113
python/ql/src/semmle/python/dataflow/new/internal/LocalSources.qll
This file contains hidden or 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,113 @@ | ||
| /** | ||
| * Provides support for intra-procedural tracking of a customizable | ||
| * set of data flow nodes. | ||
| * | ||
| * Note that unlike `TypeTracker.qll`, this library only performs | ||
| * local tracking within a function. | ||
| */ | ||
|
|
||
| import python | ||
| import DataFlowPublic | ||
| private import DataFlowPrivate | ||
|
|
||
| private predicate comes_from_cfgnode(Node node) { | ||
| exists(CfgNode first, Node second | | ||
| simpleLocalFlowStep(first, second) and | ||
| simpleLocalFlowStep*(second, node) | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * A data flow node that is a source of local flow. This includes things like | ||
| * - Expressions | ||
| * - Function parameters | ||
| */ | ||
| class LocalSourceNode extends Node { | ||
| cached | ||
| LocalSourceNode() { | ||
| not comes_from_cfgnode(this) and | ||
| not this instanceof ModuleVariableNode | ||
| or | ||
| this = any(ModuleVariableNode mvn).getARead() | ||
| } | ||
|
|
||
| /** Holds if this `LocalSourceNode` can flow to `nodeTo` in one or more local flow steps. */ | ||
| pragma[inline] | ||
| predicate flowsTo(Node nodeTo) { Cached::hasLocalSource(nodeTo, this) } | ||
|
|
||
| /** | ||
| * Gets a reference (read or write) of attribute `attrName` on this node. | ||
| */ | ||
| AttrRef getAnAttributeReference(string attrName) { Cached::namedAttrRef(this, attrName, result) } | ||
|
|
||
| /** | ||
| * Gets a read of attribute `attrName` on this node. | ||
| */ | ||
| AttrRead getAnAttributeRead(string attrName) { result = getAnAttributeReference(attrName) } | ||
|
|
||
| /** | ||
| * Gets a reference (read or write) of any attribute on this node. | ||
| */ | ||
| AttrRef getAnAttributeReference() { | ||
| Cached::namedAttrRef(this, _, result) | ||
| or | ||
| Cached::dynamicAttrRef(this, result) | ||
| } | ||
|
|
||
| /** | ||
| * Gets a read of any attribute on this node. | ||
| */ | ||
| AttrRead getAnAttributeRead() { result = getAnAttributeReference() } | ||
|
|
||
| /** | ||
| * Gets a call to this node. | ||
| */ | ||
| CallCfgNode getACall() { Cached::call(this, result) } | ||
| } | ||
|
|
||
| cached | ||
| private module Cached { | ||
| /** | ||
| * Holds if `source` is a `LocalSourceNode` that can reach `sink` via local flow steps. | ||
| * | ||
| * The slightly backwards parametering ordering is to force correct indexing. | ||
| */ | ||
| cached | ||
| predicate hasLocalSource(Node sink, LocalSourceNode source) { | ||
| source = sink | ||
| or | ||
| exists(Node second | | ||
| simpleLocalFlowStep(source, second) and | ||
| simpleLocalFlowStep*(second, sink) | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Holds if `base` flows to the base of `ref` and `ref` has attribute name `attr`. | ||
| */ | ||
| cached | ||
| predicate namedAttrRef(LocalSourceNode base, string attr, AttrRef ref) { | ||
| base.flowsTo(ref.getObject()) and | ||
| ref.getAttributeName() = attr | ||
| } | ||
|
|
||
| /** | ||
| * Holds if `base` flows to the base of `ref` and `ref` has no known attribute name. | ||
| */ | ||
| cached | ||
| predicate dynamicAttrRef(LocalSourceNode base, AttrRef ref) { | ||
| base.flowsTo(ref.getObject()) and | ||
| not exists(ref.getAttributeName()) | ||
| } | ||
|
|
||
| /** | ||
| * Holds if `func` flows to the callee of `call`. | ||
| */ | ||
| cached | ||
| predicate call(LocalSourceNode func, CallCfgNode call) { | ||
| exists(CfgNode n | | ||
| func.flowsTo(n) and | ||
| n = call.getFunction() | ||
| ) | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.