Skip to content

Commit 059dea7

Browse files
committed
Python: Fix os.path.samefile modeling
1 parent d309e15 commit 059dea7

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -959,13 +959,18 @@ private module StdlibPrivate {
959959
}
960960
}
961961

962-
/** A call to `os.path.samefile` will raise an exception if an `os.stat()` call on either pathname fails. */
962+
/**
963+
* A call to `os.path.samefile` will raise an exception if an `os.stat()` call on either pathname fails.
964+
*
965+
* See https://docs.python.org/3.10/library/os.path.html#os.path.samefile
966+
*/
963967
private class OsPathSamefileCall extends FileSystemAccess::Range, DataFlow::CallCfgNode {
964968
OsPathSamefileCall() { this = OS::path().getMember("samefile").getACall() }
965969

966970
override DataFlow::Node getAPathArgument() {
967971
result in [
968-
this.getArg(0), this.getArgByName("path1"), this.getArg(1), this.getArgByName("path2")
972+
// note that the f1/f2 names doesn't match the documentation, but is what actually works (tested on 3.8.10)
973+
this.getArg(0), this.getArgByName("f1"), this.getArg(1), this.getArgByName("f2")
969974
]
970975
}
971976
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ def through_function(open_file):
4848
os.path.ismount("path") # $ getAPathArgument="path"
4949
os.path.ismount(path="path") # $ getAPathArgument="path"
5050

51+
os.path.samefile("f1", "f2") # $ getAPathArgument="f1" getAPathArgument="f2"
52+
os.path.samefile(f1="f1", f2="f2") # $ getAPathArgument="f1" getAPathArgument="f2"
53+
5154
# actual os.path implementations
5255
import posixpath
5356
import ntpath
@@ -269,4 +272,4 @@ def test_fspath():
269272
shutil.copystat(src="src", dst="dst") # $ getAPathArgument="src" getAPathArgument="dst"
270273

271274
shutil.disk_usage("path") # $ getAPathArgument="path"
272-
shutil.disk_usage(path="path") # $ getAPathArgument="path"
275+
shutil.disk_usage(path="path") # $ getAPathArgument="path"

0 commit comments

Comments
 (0)