Skip to content

Commit 71135da

Browse files
authored
Merge pull request github#10768 from erik-krogh/fixFileLoops
JS: fix that js/file-system-race could have FPs related to loops
2 parents fa2faeb + a6c83a7 commit 71135da

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

javascript/ql/src/Security/CWE-367/FileSystemRace.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ predicate useAfterCheck(FileCheck check, FileUse use) {
106106
)
107107
)
108108
or
109-
check.getBasicBlock().getASuccessor+() = use.getBasicBlock()
109+
check.getBasicBlock().(ReachableBasicBlock).strictlyDominates(use.getBasicBlock())
110110
}
111111

112112
from FileCheck check, FileUse use
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Removed some false positives from the `js/file-system-race` query by requiring that the file-check dominates the file-access.

javascript/ql/test/query-tests/Security/CWE-367/tst.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,8 @@ const filePath3 = createFile();
4141
if (fs.existsSync(filePath3)) {
4242
fs.readFileSync(filePath3); // OK - a read after an existence check is OK
4343
}
44+
45+
const filePath4 = createFile();
46+
while(Math.random() > 0.5) {
47+
fs.open(filePath4); // OK - it is only ever opened here.
48+
}

0 commit comments

Comments
 (0)