|
14 | 14 | */ |
15 | 15 |
|
16 | 16 | import go |
17 | | -import DataFlow::PathGraph |
18 | 17 |
|
19 | 18 | /** |
20 | 19 | * Holds if a `flag` for use with `os.OpenFile` implies that the resulting |
@@ -124,25 +123,23 @@ predicate isHandledSync(DataFlow::Node sink, DataFlow::CallNode syncCall) { |
124 | 123 | not unhandledCall(syncCall) |
125 | 124 | } |
126 | 125 |
|
127 | | -/** |
128 | | - * A data flow configuration which traces writable file handles resulting from calls to |
129 | | - * `os.OpenFile` to `os.File.Close` calls on them. |
130 | | - */ |
131 | | -class UnhandledFileCloseDataFlowConfiguration extends DataFlow::Configuration { |
132 | | - UnhandledFileCloseDataFlowConfiguration() { this = "UnhandledCloseWritableHandle" } |
133 | | - |
134 | | - override predicate isSource(DataFlow::Node source) { isWritableFileHandle(source, _) } |
| 126 | +module UnhandledFileCloseConfig implements DataFlow::ConfigSig { |
| 127 | + predicate isSource(DataFlow::Node source) { isWritableFileHandle(source, _) } |
135 | 128 |
|
136 | | - override predicate isSink(DataFlow::Node sink) { isCloseSink(sink, _) } |
| 129 | + predicate isSink(DataFlow::Node sink) { isCloseSink(sink, _) } |
137 | 130 | } |
138 | 131 |
|
| 132 | +module UnhandledFileCloseFlow = DataFlow::Global<UnhandledFileCloseConfig>; |
| 133 | + |
| 134 | +import UnhandledFileCloseFlow::PathGraph |
| 135 | + |
139 | 136 | from |
140 | | - UnhandledFileCloseDataFlowConfiguration cfg, DataFlow::PathNode source, |
141 | | - DataFlow::CallNode openCall, DataFlow::PathNode sink, DataFlow::CallNode closeCall |
| 137 | + UnhandledFileCloseFlow::PathNode source, DataFlow::CallNode openCall, |
| 138 | + UnhandledFileCloseFlow::PathNode sink, DataFlow::CallNode closeCall |
142 | 139 | where |
143 | 140 | // find data flow from an `os.OpenFile` call to an `os.File.Close` call |
144 | 141 | // where the handle is writable |
145 | | - cfg.hasFlowPath(source, sink) and |
| 142 | + UnhandledFileCloseFlow::flowPath(source, sink) and |
146 | 143 | isWritableFileHandle(source.getNode(), openCall) and |
147 | 144 | // get the `CallNode` corresponding to the sink |
148 | 145 | isCloseSink(sink.getNode(), closeCall) |
|
0 commit comments