Skip to content

Commit 3707792

Browse files
committed
recognize reading/wrinting calls to fstream methods
1 parent 451ae7b commit 3707792

File tree

1 file changed

+27
-3
lines changed
  • javascript/ql/src/semmle/javascript/frameworks

1 file changed

+27
-3
lines changed

javascript/ql/src/semmle/javascript/frameworks/Files.qll

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,14 @@ private module FStream {
151151
/**
152152
* Gets a reference to a method in the `fstream` library.
153153
*/
154-
private DataFlow::SourceNode getAnFStreamProperty() {
154+
private DataFlow::SourceNode getAnFStreamProperty(boolean writer) {
155155
exists(DataFlow::SourceNode mod, string readOrWrite, string subMod |
156156
mod = DataFlow::moduleImport("fstream") and
157-
(readOrWrite = "Reader" or readOrWrite = "Writer") and
157+
(
158+
readOrWrite = "Reader" and writer = false
159+
or
160+
readOrWrite = "Writer" and writer = true
161+
) and
158162
(subMod = "File" or subMod = "Dir" or subMod = "Link" or subMod = "Proxy")
159163
|
160164
result = mod.getAPropertyRead(readOrWrite) or
@@ -167,7 +171,9 @@ private module FStream {
167171
* An invocation of a method defined in the `fstream` library.
168172
*/
169173
private class FStream extends FileSystemAccess, DataFlow::InvokeNode {
170-
FStream() { this = getAnFStreamProperty().getAnInvocation() }
174+
boolean writer;
175+
176+
FStream() { this = getAnFStreamProperty(writer).getAnInvocation() }
171177

172178
override DataFlow::Node getAPathArgument() {
173179
result = getOptionArgument(0, "path")
@@ -176,6 +182,24 @@ private module FStream {
176182
result = getArgument(0)
177183
}
178184
}
185+
186+
/**
187+
* An invocation of an `fstream` method that writes to a file.
188+
*/
189+
private class FStreamWriter extends FileSystemWriteAccess, FStream {
190+
FStreamWriter() { writer = true }
191+
192+
override DataFlow::Node getADataNode() { none() }
193+
}
194+
195+
/**
196+
* An invocation of an `fstream` method that reads a file.
197+
*/
198+
private class FStreamReader extends FileSystemReadAccess, FStream {
199+
FStreamReader() { writer = false }
200+
201+
override DataFlow::Node getADataNode() { none() }
202+
}
179203
}
180204

181205
/**

0 commit comments

Comments
 (0)