Skip to content

Commit 2a07441

Browse files
authored
Python: ModuleVariableNodes are not API uses
This caused some suprising test changes, where suddenly we had flow from a `ModuleVariableNode` (as a `RemoteFlowSource`) to a sink. This of course makes little sense, so instead we simply exclude these nodes as uses in the first place.
1 parent 7581cba commit 2a07441

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

python/ql/src/semmle/python/ApiGraphs.qll

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,9 @@ module API {
422422
}
423423

424424
/**
425-
* Gets a data-flow node to which `nd`, which is a use of an API-graph node, flows.
425+
* Gets a data-flow node to which `src`, which is a use of an API-graph node, flows.
426426
*
427-
* The flow from `nd` to that node may be inter-procedural.
427+
* The flow from `src` to that node may be inter-procedural.
428428
*/
429429
private DataFlow::LocalSourceNode trackUseNode(
430430
DataFlow::LocalSourceNode src, DataFlow::TypeTracker t
@@ -436,9 +436,16 @@ module API {
436436
exists(DataFlow::TypeTracker t2 | result = trackUseNode(src, t2).track(t2, t))
437437
}
438438

439+
/**
440+
* Gets a data-flow node to which `src`, which is a use of an API-graph node, flows.
441+
*
442+
* The flow from `src` to that node may be inter-procedural.
443+
*/
439444
cached
440445
DataFlow::LocalSourceNode trackUseNode(DataFlow::LocalSourceNode src) {
441-
result = trackUseNode(src, DataFlow::TypeTracker::end())
446+
result = trackUseNode(src, DataFlow::TypeTracker::end()) and
447+
// We exclude module variable nodes, as these do not correspond to real uses.
448+
not result instanceof DataFlow::ModuleVariableNode
442449
}
443450

444451
/**

0 commit comments

Comments
 (0)