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

Skip to content

Commit 6f6b3b0

Browse files
author
Max Schaefer
committed
JavaScript: Add a convenience method to SourceNode and use it in a few places.
1 parent a441bfb commit 6f6b3b0

6 files changed

Lines changed: 25 additions & 12 deletions

File tree

javascript/ql/src/Expressions/UnboundEventHandlerReceiver.ql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ private predicate isBoundInMethod(MethodDeclaration method) {
2222
or
2323
exists (string name |
2424
name = method.getName() |
25-
exists (DataFlow::Node rhs, DataFlow::MethodCallNode bind |
25+
exists (DataFlow::MethodCallNode bind |
2626
// this.<methodName> = <expr>.bind(...)
27-
thiz.hasPropertyWrite(name, rhs) and
28-
bind.flowsTo(rhs) and
27+
bind = thiz.getAPropertySource(name) and
2928
bind.getMethodName() = "bind"
3029
)
3130
or

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,13 @@ abstract class SourceNode extends DataFlow::Node {
178178
DataFlow::NewNode getAnInstantiation() {
179179
result = getAnInvocation()
180180
}
181+
182+
/**
183+
* Gets a source node whose value is stored in property `prop` of this node.
184+
*/
185+
DataFlow::SourceNode getAPropertySource(string prop) {
186+
result.flowsTo(getAPropertyWrite(prop).getRhs())
187+
}
181188
}
182189

183190
/**

javascript/ql/src/semmle/javascript/frameworks/AngularJS/AngularJSCore.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,9 @@ class GeneralDirective extends CustomDirective, MkCustomDirective {
439439
result = getMember("link")
440440
or
441441
// { link: { pre: function preLink() { ... }, post: function postLink() { ... } } }
442-
exists (DataFlow::PropWrite pwn | kind = "pre" or kind = "post" |
443-
pwn = getMember("link").getAPropertyWrite(kind) and
444-
result.flowsTo(pwn.getRhs())
442+
(
443+
(kind = "pre" or kind = "post") and
444+
result = getMember("link").getAPropertySource(kind)
445445
)
446446
or
447447
// { compile: function() { ... return link; } }
@@ -453,9 +453,9 @@ class GeneralDirective extends CustomDirective, MkCustomDirective {
453453
result = compileReturnSrc
454454
or
455455
// link = { pre: function preLink() { ... }, post: function postLink() { ... } }
456-
exists (DataFlow::PropWrite pwn | kind = "pre" or kind = "post" |
457-
pwn = compileReturnSrc.getAPropertyWrite(kind) and
458-
result.flowsTo(pwn.getRhs())
456+
(
457+
(kind = "pre" or kind = "post") and
458+
result = compileReturnSrc.getAPropertySource(kind)
459459
)
460460
)
461461
}

javascript/ql/src/semmle/javascript/frameworks/AngularJS/ServiceDefinitions.qll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -718,11 +718,10 @@ class ProviderRecipeDefinition extends RecipeDefinition {
718718
method set to your factory function is automatically created
719719
under the hood. */
720720

721-
exists(DataFlow::ThisNode thiz, DataFlow::Node rhs, InjectableFunction f |
721+
exists(DataFlow::ThisNode thiz, InjectableFunction f |
722722
f = getAFactoryFunction() and
723723
thiz.getBinder().getFunction() = f.asFunction() and
724-
thiz.hasPropertyWrite("$get", rhs) and
725-
result.flowsTo(rhs)
724+
result = thiz.getAPropertySource("$get")
726725
)
727726
}
728727

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| tst.js:2:11:10:1 | {\\n x ... }\\n} | f | tst.js:7:6:9:5 | () {\\n ... ;\\n } |
2+
| tst.js:2:11:10:1 | {\\n x ... }\\n} | func | tst.js:4:11:6:5 | functio ... ;\\n } |
3+
| tst.js:12:1:19:1 | class C ... ;\\n }\\n} | func | tst.js:13:14:15:3 | (x) {\\n ... x);\\n } |
4+
| tst.js:24:8:24:57 | <div on ... }</div> | onClick | tst.js:24:22:24:26 | click |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import javascript
2+
3+
from DataFlow::SourceNode nd, string prop
4+
select nd, prop, nd.getAPropertySource(prop)

0 commit comments

Comments
 (0)