Skip to content

Commit 16bde27

Browse files
committed
Python: add flow from methods to calls
1 parent 7cc9783 commit 16bde27

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,9 @@ private module Stdlib {
922922
or
923923
// method call
924924
returnsPath.getAttributeName() = pathlibPathMethod() and
925-
nodeTo.(DataFlow::CallCfgNode).getFunction() = returnsPath
925+
returnsPath
926+
.(DataFlow::LocalSourceNode)
927+
.flowsTo(nodeTo.(DataFlow::CallCfgNode).getFunction())
926928
) and
927929
nodeFrom = returnsPath.getObject()
928930
)
@@ -987,7 +989,7 @@ private module Stdlib {
987989
"unlink", "link_to", "write_bytes", "write_text"
988990
] and
989991
pathlibPath().flowsTo(fileAccess.getObject()) and
990-
this.getFunction() = fileAccess
992+
fileAccess.(DataFlow::LocalSourceNode).flowsTo(this.getFunction())
991993
}
992994

993995
override DataFlow::Node getAPathArgument() { result = fileAccess.getObject() }
@@ -1022,7 +1024,9 @@ private module Stdlib {
10221024
exists(DataFlow::AttrRead augmentsPath |
10231025
augmentsPath.getAttributeName() = pathlibPathInjection()
10241026
|
1025-
nodeTo.(DataFlow::CallCfgNode).getFunction() = augmentsPath and
1027+
augmentsPath
1028+
.(DataFlow::LocalSourceNode)
1029+
.flowsTo(nodeTo.(DataFlow::CallCfgNode).getFunction()) and
10261030
(
10271031
// type-preserving call
10281032
nodeFrom = augmentsPath.getObject()
@@ -1042,7 +1046,7 @@ private module Stdlib {
10421046
or
10431047
// exporting method
10441048
exportPath.getAttributeName() = pathlibPathMethodExport() and
1045-
nodeTo.(DataFlow::CallCfgNode).getFunction() = exportPath
1049+
exportPath.(DataFlow::LocalSourceNode).flowsTo(nodeTo.(DataFlow::CallCfgNode).getFunction())
10461050
|
10471051
nodeFrom = exportPath.getObject()
10481052
)

python/ql/test/library-tests/frameworks/stdlib/FileSystemAccess.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@
3434

3535
name = windows.parent.name
3636
o(name) # $getAPathArgument=name
37+
38+
wb = p.write_bytes
39+
wb(b"hello") # $getAPathArgument=p

0 commit comments

Comments
 (0)