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

Skip to content

Commit 74a4103

Browse files
authored
Merge pull request #976 from asger-semmle/closure-import-deep
Approved by esben-semmle
2 parents 00d490e + 7d14429 commit 74a4103

5 files changed

Lines changed: 33 additions & 2 deletions

File tree

javascript/ql/src/semmle/javascript/Closure.qll

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,15 @@ module Closure {
223223
or
224224
exists(DataFlow::SourceNode base, string basePath, string prop |
225225
basePath = getClosureNamespaceFromSourceNode(base) and
226-
isClosureNamespace(basePath) and
227226
node = base.getAPropertyRead(prop) and
228-
result = basePath + "." + prop
227+
result = basePath + "." + prop and
228+
// ensure finiteness
229+
(
230+
isClosureNamespace(basePath)
231+
or
232+
// direct access, no indirection
233+
node.(DataFlow::PropRead).getBase() = base
234+
)
229235
)
230236
or
231237
// Associate an access path with the immediate RHS of a store on a closure namespace.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| tests/nestedAccess.js:5:1:5:12 | fooBar.x.y.z |
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import javascript
2+
3+
select Closure::moduleImport("foo.bar.x.y.z")

javascript/ql/test/library-tests/Closure/moduleImport.expected

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
| foo.bar | tests/nestedAccess.js:3:14:3:36 | goog.re ... o.bar') |
2+
| foo.bar.x | tests/nestedAccess.js:5:1:5:8 | fooBar.x |
3+
| foo.bar.x | tests/nestedAccess.js:10:9:10:11 | z.x |
4+
| foo.bar.x.y | tests/nestedAccess.js:5:1:5:10 | fooBar.x.y |
5+
| foo.bar.x.y.z | tests/nestedAccess.js:5:1:5:12 | fooBar.x.y.z |
16
| goog | tests/es6Module.js:1:1:1:4 | goog |
27
| goog | tests/es6ModuleDefault.js:1:1:1:4 | goog |
38
| goog | tests/globalModule.js:1:1:1:4 | goog |
49
| goog | tests/globalModuleDefault.js:1:1:1:4 | goog |
510
| goog | tests/googModule.js:1:1:1:4 | goog |
611
| goog | tests/googModuleDefault.js:1:1:1:4 | goog |
12+
| goog | tests/nestedAccess.js:1:1:1:4 | goog |
13+
| goog | tests/nestedAccess.js:3:14:3:17 | goog |
714
| goog | tests/requireFromEs6.js:3:20:3:23 | goog |
815
| goog | tests/requireFromEs6.js:4:27:4:30 | goog |
916
| goog | tests/requireFromEs6.js:6:17:6:20 | goog |
@@ -29,12 +36,14 @@
2936
| goog.declareModuleId | tests/es6ModuleDefault.js:1:1:1:20 | goog.declareModuleId |
3037
| goog.module | tests/googModule.js:1:1:1:11 | goog.module |
3138
| goog.module | tests/googModuleDefault.js:1:1:1:11 | goog.module |
39+
| goog.module | tests/nestedAccess.js:1:1:1:11 | goog.module |
3240
| goog.module | tests/requireFromGoogModule.js:1:1:1:11 | goog.module |
3341
| goog.module | tests/uri.js:1:1:1:11 | goog.module |
3442
| goog.net | tests/uri.js:3:11:3:34 | goog.re ... g.net') |
3543
| goog.net.Uri | tests/uri.js:5:5:5:11 | net.Uri |
3644
| goog.provide | tests/globalModule.js:1:1:1:12 | goog.provide |
3745
| goog.provide | tests/globalModuleDefault.js:1:1:1:12 | goog.provide |
46+
| goog.require | tests/nestedAccess.js:3:14:3:25 | goog.require |
3847
| goog.require | tests/requireFromEs6.js:3:20:3:31 | goog.require |
3948
| goog.require | tests/requireFromEs6.js:4:27:4:38 | goog.require |
4049
| goog.require | tests/requireFromEs6.js:6:17:6:28 | goog.require |
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
goog.module('enumuse');
2+
3+
let fooBar = goog.require('foo.bar');
4+
5+
fooBar.x.y.z;
6+
7+
function infinite() {
8+
let z = fooBar;
9+
while (z) {
10+
z = z.x;
11+
}
12+
}

0 commit comments

Comments
 (0)