Skip to content

Commit dcdb2e5

Browse files
committed
JS: Fix callback check so it works without parameters
1 parent b7dd455 commit dcdb2e5

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

javascript/ql/lib/semmle/javascript/internal/flow_summaries/ExceptionFlow.qll

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ private import semmle.javascript.dataflow.internal.AdditionalFlowInternal
88
private import semmle.javascript.dataflow.FlowSummary
99
private import semmle.javascript.internal.flow_summaries.Promises
1010

11+
private predicate isCallback(DataFlow::SourceNode node) {
12+
node instanceof DataFlow::FunctionNode
13+
or
14+
node instanceof DataFlow::PartialInvokeNode
15+
or
16+
exists(DataFlow::SourceNode prev |
17+
isCallback(prev) and
18+
DataFlow::argumentPassingStep(_, prev.getALocalUse(), _, node)
19+
)
20+
}
21+
1122
/**
1223
* Summary that propagates exceptions out of callbacks back to the caller.
1324
*/
@@ -21,7 +32,7 @@ private class ExceptionFlowSummary extends SummarizedCallable {
2132
["then", "catch", "finally", "addEventListener", EventEmitter::on()] and
2233
not result = promiseConstructorRef().getAnInvocation() and
2334
// Restrict to cases where a callback is known to flow in, as lambda flow in DataFlowImplCommon blows up otherwise
24-
exists(result.getABoundCallbackParameter(_, _))
35+
isCallback(result.getAnArgument().getALocalSource())
2536
}
2637

2738
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {

javascript/ql/test/library-tests/TripleDot/exceptions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function e1() {
1313
throw source('e1.3'); // Same as e1.2 but without callback parameters
1414
});
1515
} catch (err) {
16-
sink(err); // $ hasValueFlow=e1.2 MISSING: hasValueFlow=e1.1 hasValueFlow=e1.3
16+
sink(err); // $ hasValueFlow=e1.2 hasValueFlow=e1.3 MISSING: hasValueFlow=e1.1
1717
}
1818
}
1919

@@ -47,7 +47,7 @@ function e3() {
4747
throw source('e3.4');
4848
});
4949
} catch (err) {
50-
sink(err); // $ MISSING: hasValueFlow=e3.4
50+
sink(err); // $ hasValueFlow=e3.4
5151
}
5252
}
5353

0 commit comments

Comments
 (0)