Skip to content

Commit ffc69cb

Browse files
committed
JS: Summarize functions in type tracking
1 parent 3479f02 commit ffc69cb

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

javascript/ql/src/semmle/javascript/dataflow/TypeTracking.qll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,20 @@ module StepSummary {
107107
pred = DataFlow::globalAccessPathRootPseudoNode() and
108108
summary = LoadStep(name)
109109
)
110+
or
111+
// Summarize calls with flow directly from a parameter to a return.
112+
exists(DataFlow::ParameterNode param, DataFlow::FunctionNode fun |
113+
param.flowsTo(fun.getAReturn()) and
114+
summary = LevelStep() and
115+
if param = fun.getAParameter() then (
116+
// Step from argument to call site.
117+
argumentPassing(succ, pred, fun.getFunction(), param)
118+
) else (
119+
// Step from captured parameter to local call sites
120+
pred = param and
121+
succ = fun.getAnInvocation()
122+
)
123+
)
110124
}
111125
}
112126

javascript/ql/test/library-tests/TypeTracking/ClassStyle.expected

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@ test_Connection
2626
| tst.js:78:35:78:49 | getConnection() |
2727
| tst.js:80:16:80:19 | conn |
2828
| tst.js:84:22:84:22 | x |
29-
| tst.js:96:7:96:21 | getConnection() |
29+
| tst.js:88:3:88:16 | innerCapture() |
30+
| tst.js:89:3:89:17 | innerCall(conn) |
31+
| tst.js:93:5:93:18 | innerCapture() |
32+
| tst.js:99:7:99:21 | getConnection() |
33+
| tst.js:100:12:100:26 | getConnection() |
34+
| tst.js:103:17:103:17 | x |
35+
| tst.js:104:10:106:6 | (functi ... \\n })() |
36+
| tst.js:108:1:108:23 | shared( ... tion()) |
37+
| tst.js:108:8:108:22 | getConnection() |
3038
| tst_conflict.js:6:38:6:77 | api.cha ... ction() |
3139
test_DataCallback
3240
| client.js:3:28:3:34 | x => {} |
@@ -38,6 +46,7 @@ test_DataCallback
3846
| tst.js:40:32:40:45 | getDataCurry() |
3947
| tst.js:45:19:45:20 | cb |
4048
| tst.js:48:32:48:60 | identit ... llback) |
49+
| tst.js:51:1:51:37 | functio ... ata) {} |
4150
| tst.js:58:16:58:22 | x => {} |
4251
| tst.js:68:16:70:3 | data => ... a);\\n } |
4352
test_DataValue
@@ -46,5 +55,6 @@ test_DataValue
4655
| tst.js:25:19:25:22 | data |
4756
| tst.js:33:17:33:20 | data |
4857
| tst.js:38:10:38:13 | data |
58+
| tst.js:51:30:51:33 | data |
4959
| tst.js:58:16:58:16 | x |
5060
| tst.js:68:16:68:19 | data |

javascript/ql/test/library-tests/TypeTracking/PredicateStyle.expected

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ connection
1414
| type tracker with call steps | tst.js:11:5:11:19 | this.connection |
1515
| type tracker with call steps | tst.js:80:16:80:19 | conn |
1616
| type tracker with call steps | tst.js:84:22:84:22 | x |
17+
| type tracker with call steps | tst.js:88:3:88:16 | innerCapture() |
18+
| type tracker with call steps | tst.js:89:3:89:17 | innerCall(conn) |
19+
| type tracker with call steps | tst.js:93:5:93:18 | innerCapture() |
20+
| type tracker with call steps | tst.js:103:17:103:17 | x |
21+
| type tracker with call steps | tst.js:104:10:106:6 | (functi ... \\n })() |
1722
| type tracker with call steps with property connection | tst.js:7:14:7:13 | this |
1823
| type tracker without call steps | client.js:1:10:1:27 | exportedConnection |
1924
| type tracker without call steps | tst.js:16:10:16:49 | api.cha ... ction() |
@@ -27,7 +32,10 @@ connection
2732
| type tracker without call steps | tst.js:63:38:63:77 | api.cha ... ction() |
2833
| type tracker without call steps | tst.js:67:14:67:47 | MyAppli ... nection |
2934
| type tracker without call steps | tst.js:78:35:78:49 | getConnection() |
30-
| type tracker without call steps | tst.js:96:7:96:21 | getConnection() |
35+
| type tracker without call steps | tst.js:99:7:99:21 | getConnection() |
36+
| type tracker without call steps | tst.js:100:12:100:26 | getConnection() |
37+
| type tracker without call steps | tst.js:108:1:108:23 | shared( ... tion()) |
38+
| type tracker without call steps | tst.js:108:8:108:22 | getConnection() |
3139
| type tracker without call steps | tst_conflict.js:6:38:6:77 | api.cha ... ction() |
3240
| type tracker without call steps with property MyApplication.namespace.connection | file://:0:0:0:0 | global access path |
3341
| type tracker without call steps with property conflict | tst.js:63:3:63:25 | MyAppli ... mespace |
@@ -43,6 +51,7 @@ dataCallback
4351
| tst.js:40:32:40:45 | getDataCurry() |
4452
| tst.js:45:19:45:20 | cb |
4553
| tst.js:48:32:48:60 | identit ... llback) |
54+
| tst.js:51:1:51:37 | functio ... ata) {} |
4655
| tst.js:58:16:58:22 | x => {} |
4756
| tst.js:68:16:70:3 | data => ... a);\\n } |
4857
dataValue
@@ -51,5 +60,6 @@ dataValue
5160
| tst.js:25:19:25:22 | data |
5261
| tst.js:33:17:33:20 | data |
5362
| tst.js:38:10:38:13 | data |
63+
| tst.js:51:30:51:33 | data |
5464
| tst.js:58:16:58:16 | x |
5565
| tst.js:68:16:68:19 | data |

javascript/ql/test/library-tests/TypeTracking/tst.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,18 @@ function outer(conn) {
9292
function otherInner() {
9393
innerCapture();
9494
}
95+
return class {
96+
get() { return conn }
97+
}
9598
}
9699
outer(getConnection());
100+
new (outer(getConnection())).get();
101+
new (outer(somethingElse())).get();
102+
103+
function shared(x) {
104+
return (function() {
105+
return x;
106+
})();
107+
}
108+
shared(getConnection());
109+
shared(somethingElse());

0 commit comments

Comments
 (0)