mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
Merge pull request #1608 from asger-semmle/thisnode-basicblock
Approved by xiemaisi
This commit is contained in:
@@ -788,6 +788,10 @@ module DataFlow {
|
||||
function.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
|
||||
}
|
||||
|
||||
override BasicBlock getBasicBlock() {
|
||||
result = function.(ExprOrStmt).getBasicBlock()
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the function corresponding to this exceptional return node.
|
||||
*/
|
||||
@@ -810,6 +814,10 @@ module DataFlow {
|
||||
invoke.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
|
||||
}
|
||||
|
||||
override BasicBlock getBasicBlock() {
|
||||
result = invoke.getBasicBlock()
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the invocation corresponding to this exceptional return node.
|
||||
*/
|
||||
@@ -991,6 +999,30 @@ module DataFlow {
|
||||
override ControlFlowNode getWriteNode() { result = arr }
|
||||
}
|
||||
|
||||
/**
|
||||
* A data flow node representing `this` in a function or top-level.
|
||||
*/
|
||||
private class ThisNodeInternal extends Node, TThisNode {
|
||||
override string toString() { result = "this" }
|
||||
|
||||
override BasicBlock getBasicBlock() {
|
||||
exists(StmtContainer container | this = TThisNode(container) |
|
||||
result = container.getEntry()
|
||||
)
|
||||
}
|
||||
|
||||
override predicate hasLocationInfo(
|
||||
string filepath, int startline, int startcolumn, int endline, int endcolumn
|
||||
) {
|
||||
// Use the function entry as the location
|
||||
exists(StmtContainer container | this = TThisNode(container) |
|
||||
container.getEntry()
|
||||
.getLocation()
|
||||
.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the data flow node corresponding to `nd`.
|
||||
*
|
||||
|
||||
@@ -276,18 +276,6 @@ class ThisNode extends DataFlow::Node, DataFlow::SourceNode {
|
||||
* which is the nearest enclosing non-arrow function or top-level.
|
||||
*/
|
||||
StmtContainer getBindingContainer() { DataFlow::thisNode(this, result) }
|
||||
|
||||
override string toString() { result = "this" }
|
||||
|
||||
override predicate hasLocationInfo(
|
||||
string filepath, int startline, int startcolumn, int endline, int endcolumn
|
||||
) {
|
||||
// Use the function entry as the location
|
||||
getBindingContainer()
|
||||
.getEntry()
|
||||
.getLocation()
|
||||
.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
|
||||
}
|
||||
}
|
||||
|
||||
/** A data flow node corresponding to a global variable access. */
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
| tst.js:1:10:1:11 | fs |
|
||||
| tst.js:1:10:1:11 | fs |
|
||||
| tst.js:1:20:1:23 | 'fs' |
|
||||
@@ -0,0 +1,5 @@
|
||||
import javascript
|
||||
|
||||
from DataFlow::Node node
|
||||
where not exists(node.getBasicBlock())
|
||||
select node
|
||||
@@ -0,0 +1,46 @@
|
||||
missingBasicBlock
|
||||
basicBlock
|
||||
| tst.js:1:1:1:0 | this | tst.js:1:1:1:0 | entry node of <toplevel> |
|
||||
| tst.js:1:16:1:15 | this | tst.js:1:16:1:15 | entry node of () {} |
|
||||
| tst.js:3:7:3:6 | this | tst.js:3:7:3:6 | entry node of () {\\n ... ;\\n } |
|
||||
| tst.js:7:7:7:6 | this | tst.js:7:7:7:6 | entry node of () {\\n ... ;\\n } |
|
||||
| tst.js:13:14:13:13 | this | tst.js:13:14:13:13 | entry node of () {} |
|
||||
| tst.js:15:13:15:12 | this | tst.js:15:13:15:12 | entry node of () {\\n ... ;\\n } |
|
||||
| tst.js:16:10:16:9 | this | tst.js:16:10:16:9 | entry node of functio ... } |
|
||||
| tst.js:21:13:21:12 | this | tst.js:21:13:21:12 | entry node of () {\\n ... ;\\n } |
|
||||
| tst.js:23:10:23:9 | this | tst.js:23:10:23:9 | entry node of functio ... } |
|
||||
| tst.js:28:13:28:12 | this | tst.js:28:13:28:12 | entry node of () {\\n ... ;\\n } |
|
||||
| tst.js:29:9:29:8 | this | tst.js:29:9:29:8 | entry node of functio ... } |
|
||||
| tst.js:35:13:35:12 | this | tst.js:35:13:35:12 | entry node of () {\\n ... ;\\n } |
|
||||
| tst.js:36:10:36:9 | this | tst.js:36:10:36:9 | entry node of functio ... } |
|
||||
| tst.js:37:14:37:13 | this | tst.js:37:14:37:13 | entry node of functio ... } |
|
||||
| tst.js:45:14:45:13 | this | tst.js:45:14:45:13 | entry node of () {} |
|
||||
| tst.js:47:13:47:12 | this | tst.js:47:13:47:12 | entry node of () {\\n ... ;\\n } |
|
||||
| tst.js:48:10:48:9 | this | tst.js:48:10:48:9 | entry node of functio ... } |
|
||||
| tst.js:55:15:55:14 | this | tst.js:55:15:55:14 | entry node of () {} |
|
||||
| tst.js:57:13:57:12 | this | tst.js:57:13:57:12 | entry node of () {\\n ... ;\\n } |
|
||||
| tst.js:59:10:59:9 | this | tst.js:59:10:59:9 | entry node of functio ... } |
|
||||
| tst.js:66:13:66:12 | this | tst.js:66:13:66:12 | entry node of () {} |
|
||||
| tst.js:68:13:68:12 | this | tst.js:68:13:68:12 | entry node of () {\\n ... ;\\n } |
|
||||
| tst.js:69:15:69:14 | this | tst.js:69:15:69:14 | entry node of functio ... } |
|
||||
| tst.js:74:13:74:12 | this | tst.js:74:13:74:12 | entry node of () {\\n ... )\\n } |
|
||||
| tst.js:76:10:76:9 | this | tst.js:76:10:76:9 | entry node of functio ... } |
|
||||
| tst.js:83:22:83:21 | this | tst.js:83:22:83:21 | entry node of () {} |
|
||||
| tst.js:85:13:85:12 | this | tst.js:85:13:85:12 | entry node of () {\\n ... `\\n } |
|
||||
| tst.js:87:21:87:20 | this | tst.js:87:21:87:20 | entry node of functio ... } |
|
||||
| tst.js:95:13:95:12 | this | tst.js:95:13:95:12 | entry node of () {\\n ... ;\\n } |
|
||||
| tst.js:96:9:96:8 | this | tst.js:96:9:96:8 | entry node of functio ... } |
|
||||
| tst.js:105:20:105:19 | this | tst.js:105:20:105:19 | entry node of () {} |
|
||||
| tst.js:107:13:107:12 | this | tst.js:107:13:107:12 | entry node of () {\\n ... ;\\n } |
|
||||
| tst.js:108:18:108:17 | this | tst.js:108:18:108:17 | entry node of functio ... } |
|
||||
| tst.js:113:13:113:12 | this | tst.js:113:13:113:12 | entry node of () {\\n ... ;\\n } |
|
||||
| tst.js:114:21:114:20 | this | tst.js:114:21:114:20 | entry node of functio ... } |
|
||||
| tst.js:119:13:119:12 | this | tst.js:119:13:119:12 | entry node of () {\\n ... ;\\n } |
|
||||
| tst.js:120:27:120:26 | this | tst.js:120:27:120:26 | entry node of functio ... } |
|
||||
| tst.js:128:16:128:15 | this | tst.js:128:16:128:15 | entry node of () {} |
|
||||
| tst.js:130:13:130:12 | this | tst.js:130:13:130:12 | entry node of () {\\n ... ;\\n } |
|
||||
| tst.js:131:18:131:17 | this | tst.js:131:18:131:17 | entry node of functio ... } |
|
||||
| tst.js:136:13:136:12 | this | tst.js:136:13:136:12 | entry node of () {\\n ... ;\\n } |
|
||||
| tst.js:137:21:137:20 | this | tst.js:137:21:137:20 | entry node of functio ... } |
|
||||
| tst.js:142:13:142:12 | this | tst.js:142:13:142:12 | entry node of () {\\n ... ;\\n } |
|
||||
| tst.js:143:23:143:22 | this | tst.js:143:23:143:22 | entry node of functio ... } |
|
||||
@@ -0,0 +1,9 @@
|
||||
import javascript
|
||||
|
||||
query predicate missingBasicBlock(DataFlow::ThisNode node) {
|
||||
not exists(node.getBasicBlock())
|
||||
}
|
||||
|
||||
query BasicBlock basicBlock(DataFlow::ThisNode node) {
|
||||
result = node.getBasicBlock()
|
||||
}
|
||||
Reference in New Issue
Block a user