Skip to content

Commit a91208f

Browse files
committed
Python: Fix kwarg modeling for os.path.isdir
1 parent 36f14b3 commit a91208f

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -318,20 +318,26 @@ private module StdlibPrivate {
318318
* - https://docs.python.org/3/library/os.path.html#os.path.realpath
319319
*/
320320
private class OsPathProbingCall extends FileSystemAccess::Range, DataFlow::CallCfgNode {
321+
string name;
322+
321323
OsPathProbingCall() {
322-
this =
323-
os::path()
324-
.getMember([
325-
// these check if the file exists
326-
"exists", "lexists", "isfile", "isdir", "islink", "ismount",
327-
// these raise errors if the file does not exist
328-
"getatime", "getmtime", "getctime", "getsize"
329-
])
330-
.getACall()
324+
name in [
325+
// these check if the file exists
326+
"exists", "lexists", "isfile", "isdir", "islink", "ismount",
327+
// these raise errors if the file does not exist
328+
"getatime", "getmtime", "getctime", "getsize"
329+
] and
330+
this = os::path().getMember(name).getACall()
331331
}
332332

333333
override DataFlow::Node getAPathArgument() {
334+
not name = "isdir" and
334335
result in [this.getArg(0), this.getArgByName("path")]
336+
or
337+
// although the Python docs say the parameter is called `path`, the implementation
338+
// actually uses `s`.
339+
name = "isdir" and
340+
result in [this.getArg(0), this.getArgByName("s")]
335341
}
336342
}
337343

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def through_function(open_file):
3737
os.path.isfile(path="path") # $ getAPathArgument="path"
3838

3939
os.path.isdir("s") # $ getAPathArgument="s"
40-
os.path.isdir(s="s") # $ MISSING: getAPathArgument="s"
40+
os.path.isdir(s="s") # $ getAPathArgument="s"
4141

4242
os.path.islink("path") # $ getAPathArgument="path"
4343
os.path.islink(path="path") # $ getAPathArgument="path"

0 commit comments

Comments
 (0)