|
3 | 3 | * @description Errors which occur when closing a writable file handle may result in data loss |
4 | 4 | * if the data could not be successfully flushed. Such errors should be handled |
5 | 5 | * explicitly. |
6 | | - * @kind problem |
| 6 | + * @kind path-problem |
7 | 7 | * @problem.severity warning |
8 | 8 | * @precision high |
9 | 9 | * @id go/unhandled-writable-file-close |
|
14 | 14 | */ |
15 | 15 |
|
16 | 16 | import go |
| 17 | +import DataFlow::PathGraph |
17 | 18 |
|
18 | 19 | /** |
19 | 20 | * Holds if a `flag` for use with `os.OpenFile` implies that the resulting |
@@ -142,18 +143,18 @@ predicate precededBySync(DataFlow::Node node, DataFlow::CallNode call) { |
142 | 143 | } |
143 | 144 |
|
144 | 145 | from |
145 | | - UnhandledFileCloseDataFlowConfiguration cfg, DataFlow::Node source, DataFlow::CallNode openCall, |
146 | | - DataFlow::Node sink, DataFlow::CallNode closeCall |
| 146 | + UnhandledFileCloseDataFlowConfiguration cfg, DataFlow::PathNode source, |
| 147 | + DataFlow::CallNode openCall, DataFlow::PathNode sink, DataFlow::CallNode closeCall |
147 | 148 | where |
148 | 149 | // find data flow from an `os.OpenFile` call to an `os.File.Close` call |
149 | 150 | // where the handle is writable |
150 | | - cfg.hasFlow(source, sink) and |
151 | | - isWritableFileHandle(source, openCall) and |
| 151 | + cfg.hasFlowPath(source, sink) and |
| 152 | + isWritableFileHandle(source.getNode(), openCall) and |
152 | 153 | // get the `CallNode` corresponding to the sink |
153 | | - isCloseSink(sink, closeCall) and |
| 154 | + isCloseSink(sink.getNode(), closeCall) and |
154 | 155 | // check that the call to `os.File.Close` is not preceded by a checked call to |
155 | 156 | // `os.File.Sync` |
156 | | - not precededBySync(sink, closeCall) |
157 | | -select sink, |
| 157 | + not precededBySync(sink.getNode(), closeCall) |
| 158 | +select sink, source, sink, |
158 | 159 | "File handle may be writable as a result of data flow from a $@ and closing it may result in data loss upon failure, which is not handled explicitly.", |
159 | 160 | openCall, openCall.toString() |
0 commit comments