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

Skip to content

Commit e0b2579

Browse files
committed
remove type-tracking from getAReference, and rewrite qldocs
1 parent 6544170 commit e0b2579

2 files changed

Lines changed: 25 additions & 15 deletions

File tree

javascript/ql/src/semmle/javascript/ApiGraphs.qll

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,44 @@ module API {
2121
*/
2222
class Node extends Impl::TApiNode {
2323
/**
24-
* Gets a `SourceNode` corresponding to a use of the API component represented by this node.
24+
* Gets a data-flow corresponding to a use of the API component represented by this node.
2525
*
2626
* For example, `require('fs').readFileSync` is a use of the function `readFileSync` from the
27-
* `fs` module, and `require('fs').readFileSync(file)` is a use of the result of that function.
27+
* `fs` module, and `require('fs').readFileSync(file)` is a use of the return of that function.
28+
*
29+
* The use is type-tracked, meaning that in `f(obj.foo); function f(x) {};` both `obj.foo` and
30+
* `x` are uses of the `foo` member from `obj`.
2831
*
2932
* As another example, in the assignment `exports.plusOne = (x) => x+1` the two references to
3033
* `x` are uses of the first parameter of `plusOne`.
31-
*
32-
* Note: The result from this predicate is always a `DataFlow::SourceǸode`, use `getAUse()` if
33-
* you want to follow purely local data-flow and get all `DataFlow::Node`s that corrospond to a
34-
* use of this API node.
3534
*/
36-
DataFlow::SourceNode getAReference() {
37-
exists(DataFlow::SourceNode src | Impl::use(this, src) | result = Impl::trackUseNode(src))
35+
DataFlow::Node getAUse() {
36+
exists(DataFlow::SourceNode src | Impl::use(this, src) |
37+
Impl::trackUseNode(src).flowsTo(result)
38+
)
3839
}
3940

4041
/**
41-
* Gets a data-flow node corresponding to a use of the API component represented by this node.
42+
* Gets a reference to the API component represented by this node.
43+
*
44+
* For example, `require('fs').readFileSync` is a reference to the `readFileSync` member from the
45+
* `fs` module.
4246
*
43-
* This predicate is similar to `getAReference`, except this prediate also follows purely local
44-
* data-flow.
47+
* No local data-flow or type-tracking happens on the result, which means that in
48+
* `const x = fs.readFile` only `fs.readFile` is a reference to the `readFile` member of `fs`,
49+
* neither `x` nor any node that `x` flows to is a reference to this API component.
50+
*/
51+
DataFlow::SourceNode getAReference() { Impl::use(this, result) }
52+
53+
/**
54+
* Gets a call to the function represented by this API component.
4555
*/
46-
DataFlow::Node getAUse() { getAReference().flowsTo(result) }
56+
DataFlow::CallNode getACall() { result = getReturn().getAReference() }
4757

4858
/**
49-
* Gets a call to a use of the API component represented by this node.
59+
* Gets an instantiation of the function represented by this API component.
5060
*/
51-
DataFlow::CallNode getACall() { result = getAReference().getACall() }
61+
DataFlow::NewNode getAnInstantiation() { result = getInstance().getAReference() }
5262

5363
/**
5464
* Gets a data-flow node corresponding to the right-hand side of a definition of the API

javascript/ql/src/semmle/javascript/frameworks/SQL.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ private module Sequelize {
300300

301301
Credentials() {
302302
exists(NewExpr ne, string prop |
303-
ne = sequelize().getAReference().getAnInstantiation().asExpr() and
303+
ne = sequelize().getAnInstantiation().asExpr() and
304304
(
305305
this = ne.getArgument(1) and prop = "username"
306306
or

0 commit comments

Comments
 (0)