Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0e1383d

Browse files
committed
Make UnhandledFileCloseWritableHandle use new API
1 parent 00cc78d commit 0e1383d

1 file changed

Lines changed: 10 additions & 13 deletions

File tree

go/ql/src/InconsistentCode/UnhandledCloseWritableHandle.ql

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
*/
1515

1616
import go
17-
import DataFlow::PathGraph
1817

1918
/**
2019
* 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) {
124123
not unhandledCall(syncCall)
125124
}
126125

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, _) }
135128

136-
override predicate isSink(DataFlow::Node sink) { isCloseSink(sink, _) }
129+
predicate isSink(DataFlow::Node sink) { isCloseSink(sink, _) }
137130
}
138131

132+
module UnhandledFileCloseFlow = DataFlow::Global<UnhandledFileCloseConfig>;
133+
134+
import UnhandledFileCloseFlow::PathGraph
135+
139136
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
142139
where
143140
// find data flow from an `os.OpenFile` call to an `os.File.Close` call
144141
// where the handle is writable
145-
cfg.hasFlowPath(source, sink) and
142+
UnhandledFileCloseFlow::flowPath(source, sink) and
146143
isWritableFileHandle(source.getNode(), openCall) and
147144
// get the `CallNode` corresponding to the sink
148145
isCloseSink(sink.getNode(), closeCall)

0 commit comments

Comments
 (0)