Merge pull request #10768 from erik-krogh/fixFileLoops

JS: fix that js/file-system-race could have FPs related to loops
This commit is contained in:
Erik Krogh Kristensen
2022-10-17 12:01:55 +02:00
committed by GitHub
3 changed files with 10 additions and 1 deletions

View File

@@ -106,7 +106,7 @@ predicate useAfterCheck(FileCheck check, FileUse use) {
)
)
or
check.getBasicBlock().getASuccessor+() = use.getBasicBlock()
check.getBasicBlock().(ReachableBasicBlock).strictlyDominates(use.getBasicBlock())
}
from FileCheck check, FileUse use

View File

@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* Removed some false positives from the `js/file-system-race` query by requiring that the file-check dominates the file-access.

View File

@@ -41,3 +41,8 @@ const filePath3 = createFile();
if (fs.existsSync(filePath3)) {
fs.readFileSync(filePath3); // OK - a read after an existence check is OK
}
const filePath4 = createFile();
while(Math.random() > 0.5) {
fs.open(filePath4); // OK - it is only ever opened here.
}