Skip to content

Commit 7500a31

Browse files
committed
fix that js/file-system-race could have FPs related to loops
1 parent 02656b1 commit 7500a31

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-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

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)