Repository navigation
Expand file tree
/
Copy pathUnresolvedCalls.ql
More file actions
58 lines (51 loc) · 1.7 KB
/
Copy pathUnresolvedCalls.ql
File metadata and controls
58 lines (51 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* @name Unresolved calls
* @description Calls that cannot be statically resolved to a target function.
* @id solidity/unresolved-calls
*/
import codeql.solidity.ast.internal.TreeSitter
import codeql.solidity.callgraph.CallResolution
/**
* Gets the function name from a function definition.
*/
string getFunctionName(Solidity::FunctionDefinition func) {
result = func.getName().(Solidity::AstNode).getValue()
}
/**
* Gets the contract name from a contract declaration.
*/
string getContractName(Solidity::ContractDeclaration contract) {
result = contract.getName().(Solidity::AstNode).getValue()
}
/**
* Gets the enclosing function of a call expression.
*/
Solidity::FunctionDefinition getEnclosingFunction(Solidity::CallExpression call) {
call.getParent+() = result
}
/**
* Gets the enclosing contract of a function.
*/
Solidity::ContractDeclaration getEnclosingContract(Solidity::FunctionDefinition func) {
func.getParent+() = result
}
/**
* Gets a string representation of the call target.
*/
string getCallTargetString(Solidity::CallExpression call) {
result = call.getFunction().(Solidity::Identifier).getValue()
or
result = call.getFunction().(Solidity::MemberExpression).getProperty().(Solidity::AstNode).getValue()
}
/** Calls the resolver could not tie to a definition, with the callee name as written. */
query predicate unresolvedCalls(
string contract, string function, string target, Solidity::CallExpression node
) {
CallResolution::isUnresolved(node) and
exists(Solidity::FunctionDefinition f |
f = getEnclosingFunction(node) and
contract = getContractName(getEnclosingContract(f)) and
function = getFunctionName(f) and
target = getCallTargetString(node)
)
}