Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1bbe1ec

Browse files
committed
the js/use-of-returnless-function query now support multiple callees
1 parent 7025ba3 commit 1bbe1ec

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

javascript/ql/src/Statements/UseOfReturnlessFunction.ql

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,15 @@ predicate callBlacklist(DataFlow::CallNode call) {
9898
exists(MethodCallExpr e | e.getCalleeName() = "resolve" and call.asExpr() = e.getArgument(0))
9999
}
100100

101-
from Function f, DataFlow::CallNode call
101+
from DataFlow::CallNode call
102102
where
103103
// Intentionally only considering very precise callee information. It makes almost no difference.
104-
f = call.getACallee(0) and
105-
count(call.getACallee(0)) = 1 and
106-
107-
not functionBlacklist(f) and
104+
not call.isIndefinite(_) and
105+
forex(Function f | f = call.getACallee() | not functionBlacklist(f)) and
108106

109107
exists(call.asExpr()) and // TODO: Need to figure out what to do about reflective calls.
110108

111109
not callBlacklist(call)
112110
select
113-
call, "the function $@ does not return anything, yet the return value is used.", f, call.getCalleeName()
111+
call, "the function $@ does not return anything, yet the return value is used.", call.getACallee(), call.getCalleeName()
114112

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
| tst.js:20:17:20:33 | onlySideEffects() | the function $@ does not return anything, yet the return value is used. | tst.js:11:5:13:5 | functio ... )\\n } | onlySideEffects |
22
| tst.js:24:13:24:29 | onlySideEffects() | the function $@ does not return anything, yet the return value is used. | tst.js:11:5:13:5 | functio ... )\\n } | onlySideEffects |
33
| tst.js:30:20:30:36 | onlySideEffects() | the function $@ does not return anything, yet the return value is used. | tst.js:11:5:13:5 | functio ... )\\n } | onlySideEffects |
4+
| tst.js:53:10:53:34 | bothOnl ... fects() | the function $@ does not return anything, yet the return value is used. | tst.js:11:5:13:5 | functio ... )\\n } | bothOnlyHaveSideEffects |
5+
| tst.js:53:10:53:34 | bothOnl ... fects() | the function $@ does not return anything, yet the return value is used. | tst.js:48:2:50:5 | functio ... )\\n } | bothOnlyHaveSideEffects |

javascript/ql/test/query-tests/Statements/UseOfReturnlessFunction/tst.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,16 @@
4444

4545
var e = myObj.onlySideEffects.apply(this, arguments); // NOT OK!
4646
console.log(e);
47+
48+
function onlySideEffects2() {
49+
console.log("Boo!")
50+
}
51+
52+
var bothOnlyHaveSideEffects = Math.random() > 0.5 ? onlySideEffects : onlySideEffects2;
53+
var f = bothOnlyHaveSideEffects(); // NOT OK!
54+
console.log(f);
55+
56+
var oneOfEach = Math.random() > 0.5 ? onlySideEffects : returnsValue;
57+
var g = oneOfEach(); // OK
58+
console.log(g);
4759
})();

0 commit comments

Comments
 (0)