Skip to content

Commit 85a3390

Browse files
committed
Make the query a path-problem
1 parent 199c864 commit 85a3390

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

go/ql/src/InconsistentCode/UnhandledCloseWritableHandle.ql

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @description Errors which occur when closing a writable file handle may result in data loss
44
* if the data could not be successfully flushed. Such errors should be handled
55
* explicitly.
6-
* @kind problem
6+
* @kind path-problem
77
* @problem.severity warning
88
* @precision high
99
* @id go/unhandled-writable-file-close
@@ -14,6 +14,7 @@
1414
*/
1515

1616
import go
17+
import DataFlow::PathGraph
1718

1819
/**
1920
* 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) {
142143
}
143144

144145
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
147148
where
148149
// find data flow from an `os.OpenFile` call to an `os.File.Close` call
149150
// 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
152153
// get the `CallNode` corresponding to the sink
153-
isCloseSink(sink, closeCall) and
154+
isCloseSink(sink.getNode(), closeCall) and
154155
// check that the call to `os.File.Close` is not preceded by a checked call to
155156
// `os.File.Sync`
156-
not precededBySync(sink, closeCall)
157-
select sink,
157+
not precededBySync(sink.getNode(), closeCall)
158+
select sink, source, sink,
158159
"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.",
159160
openCall, openCall.toString()

0 commit comments

Comments
 (0)