mirror of
https://github.com/github/codeql.git
synced 2026-02-14 22:21:06 +01:00
29 lines
792 B
Plaintext
29 lines
792 B
Plaintext
/**
|
|
* @name File is not always closed
|
|
* @description Opening a file without ensuring that it is always closed may lead to data loss or resource leaks.
|
|
* @kind problem
|
|
* @tags quality
|
|
* reliability
|
|
* correctness
|
|
* performance
|
|
* external/cwe/cwe-772
|
|
* @problem.severity warning
|
|
* @sub-severity high
|
|
* @precision high
|
|
* @id py/file-not-closed
|
|
*/
|
|
|
|
import python
|
|
import FileNotAlwaysClosedQuery
|
|
import codeql.util.Option
|
|
|
|
from FileOpen fo, string msg, LocatableOption<Location, DataFlow::Node>::Option exec
|
|
where
|
|
fileNotClosed(fo) and
|
|
msg = "File is opened but is not closed." and
|
|
exec.isNone()
|
|
or
|
|
fileMayNotBeClosedOnException(fo, exec.asSome()) and
|
|
msg = "File may not be closed if $@ raises an exception."
|
|
select fo, msg, exec, "this operation"
|