mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
JS: Handle implicit return in getImmediatePredecessor
This commit is contained in:
@@ -166,11 +166,7 @@ module DataFlow {
|
|||||||
* Gets the immediate predecessor of this node, if any.
|
* Gets the immediate predecessor of this node, if any.
|
||||||
*
|
*
|
||||||
* A node with an immediate predecessor can usually only have the value that flows
|
* A node with an immediate predecessor can usually only have the value that flows
|
||||||
* into its from its immediate predecessor, currently with one exception:
|
* into its from its immediate predecessor.
|
||||||
*
|
|
||||||
* - An immediately-invoked function expression with a single return expression `e`
|
|
||||||
* has `e` as its immediate predecessor, even if the function can fall over the
|
|
||||||
* end and return `undefined`.
|
|
||||||
*/
|
*/
|
||||||
cached
|
cached
|
||||||
DataFlow::Node getImmediatePredecessor() {
|
DataFlow::Node getImmediatePredecessor() {
|
||||||
@@ -190,11 +186,11 @@ module DataFlow {
|
|||||||
)
|
)
|
||||||
or
|
or
|
||||||
// IIFE call -> return value of IIFE
|
// IIFE call -> return value of IIFE
|
||||||
// Note: not sound in case function falls over end and returns 'undefined'
|
|
||||||
exists(Function fun |
|
exists(Function fun |
|
||||||
localCall(this.asExpr(), fun) and
|
localCall(this.asExpr(), fun) and
|
||||||
result = fun.getAReturnedExpr().flow() and
|
result = fun.getAReturnedExpr().flow() and
|
||||||
strictcount(fun.getAReturnedExpr()) = 1
|
strictcount(fun.getAReturnedExpr()) = 1 and
|
||||||
|
not fun.getExit().isJoin() // can only reach exit by the return statement
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
function test() {
|
||||||
|
let x = (function() {
|
||||||
|
if (g) return 5;
|
||||||
|
})();
|
||||||
|
if (x + 1 < 5) {} // OK
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user