Skip to content

Commit a298f5e

Browse files
committed
Ruby: Recognise File.atomic_write as a file writer
This method is an ActiveSupport extension, but there's no harm in recognising it universally as any identically-named method is likely to also be a file writer.
1 parent 0ce14fc commit a298f5e

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

ruby/ql/lib/codeql/ruby/frameworks/core/internal/IOOrFile.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class IOOrFileWriteMethodCall extends IOOrFileMethodCall {
137137
receiverKind = "class" and
138138
api = ["IO", "File"] and
139139
this = API::getTopLevelMember(api).getAMethodCall(methodName) and
140-
methodName = ["binwrite", "write"] and
140+
methodName = ["binwrite", "write", "atomic_write"] and
141141
dataNode = this.getArgument(1)
142142
or
143143
// e.g. `{IO,File}.new("foo.txt", "a+).puts("hello")`

ruby/ql/test/library-tests/frameworks/files/Files.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ fileSystemAccesses
7676
| Files.rb:41:1:41:26 | call to open |
7777
| Files.rb:41:1:41:43 | call to write |
7878
| Files.rb:48:1:48:40 | call to printf |
79+
| Files.rb:49:1:49:30 | call to write |
80+
| Files.rb:50:1:50:37 | call to atomic_write |
7981
fileNameSources
8082
| Files.rb:10:6:10:18 | call to path |
8183
| Files.rb:11:6:11:21 | call to to_path |
@@ -86,7 +88,11 @@ fileWriters
8688
| Files.rb:40:1:40:22 | call to puts |
8789
| Files.rb:41:1:41:43 | call to write |
8890
| Files.rb:48:1:48:40 | call to printf |
91+
| Files.rb:49:1:49:30 | call to write |
92+
| Files.rb:50:1:50:37 | call to atomic_write |
8993
fileSystemWriteAccesses
9094
| Files.rb:40:1:40:22 | call to puts |
9195
| Files.rb:41:1:41:43 | call to write |
9296
| Files.rb:48:1:48:40 | call to printf |
97+
| Files.rb:49:1:49:30 | call to write |
98+
| Files.rb:50:1:50:37 | call to atomic_write |

ruby/ql/test/library-tests/frameworks/files/Files.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,5 @@
4646
int_1 = 123
4747
# File/IO write
4848
io_file.printf("%s: %d\n", str_1, int_1)
49+
File.write("foo.txt", "hello")
50+
File.atomic_write("foo.txt", "hello")

0 commit comments

Comments
 (0)