mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
Python: Model functions that will raise
on non-existing files.
This commit is contained in:
@@ -196,23 +196,36 @@ private module StdlibPrivate {
|
||||
}
|
||||
|
||||
/**
|
||||
* A call to `os.path.exists` or `os.path.lexists` will check if a file exists on the file system.
|
||||
* The `os.path` module offers e number of methods for checking if a file exists and/or has certain
|
||||
* The `os.path` module offers a number of methods for checking if a file exists and/or has certain
|
||||
* properties, leading to a file system access.
|
||||
* A call to `os.path.exists` or `os.path.lexists` will check if a file exists on the file system.
|
||||
* (Although, on some platforms, the check may return `false` due to missing permissions.)
|
||||
* A call to `os.path.getatime` will raise `OSError` if the file does not exist or is inaccessible.
|
||||
* See:
|
||||
* - https://docs.python.org/3/library/os.path.html#os.path.exists
|
||||
* - https://docs.python.org/3/library/os.path.html#os.path.lexists
|
||||
* - https://docs.python.org/3/library/os.path.html#os.path.isfile
|
||||
* - https://docs.python.org/3/library/os.path.html#os.path.isdir
|
||||
* - https://docs.python.org/3/library/os.path.html#os.path.islink
|
||||
* - https://docs.python.org/3/library/os.path.html#os.path.ismount
|
||||
* - https://docs.python.org/3/library/os.path.html#os.path.exists
|
||||
* - https://docs.python.org/3/library/os.path.html#os.path.lexists
|
||||
* - https://docs.python.org/3/library/os.path.html#os.path.isfile
|
||||
* - https://docs.python.org/3/library/os.path.html#os.path.isdir
|
||||
* - https://docs.python.org/3/library/os.path.html#os.path.islink
|
||||
* - https://docs.python.org/3/library/os.path.html#os.path.ismount
|
||||
* - https://docs.python.org/3/library/os.path.html#os.path.getatime
|
||||
* - https://docs.python.org/3/library/os.path.html#os.path.getmtime
|
||||
* - https://docs.python.org/3/library/os.path.html#os.path.getctime
|
||||
* - https://docs.python.org/3/library/os.path.html#os.path.getsize
|
||||
* - https://docs.python.org/3/library/os.path.html#os.path.realpath
|
||||
*/
|
||||
private class OsPathProbingCall extends FileSystemAccess::Range, DataFlow::CallCfgNode {
|
||||
OsPathProbingCall() {
|
||||
this =
|
||||
os::path()
|
||||
.getMember(["exists", "lexists", "isfile", "isdir", "islink", "ismount"])
|
||||
.getMember([
|
||||
// these check if the file exists
|
||||
"exists", "lexists", "isfile", "isdir", "islink", "ismount",
|
||||
// these raise errors if the file does not exist
|
||||
"getatime", "getmtime", "getctime", "getsize",
|
||||
// this will resolve symlinks
|
||||
"realpath"
|
||||
])
|
||||
.getACall()
|
||||
}
|
||||
|
||||
@@ -221,6 +234,17 @@ private module StdlibPrivate {
|
||||
}
|
||||
}
|
||||
|
||||
/** A call to `os.path.samefile` will raise an exception if an `os.stat()` call on either pathname fails. */
|
||||
private class OsPathSamefileCall extends FileSystemAccess::Range, DataFlow::CallCfgNode {
|
||||
OsPathSamefileCall() { this = os::path().getMember("samefile").getACall() }
|
||||
|
||||
override DataFlow::Node getAPathArgument() {
|
||||
result in [
|
||||
this.getArg(0), this.getArgByName("path1"), this.getArg(1), this.getArgByName("path2")
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A call to `os.path.normpath`.
|
||||
* See https://docs.python.org/3/library/os.path.html#os.path.normpath
|
||||
|
||||
Reference in New Issue
Block a user