improve getSimpleAccessPath

This commit is contained in:
Esben Sparre Andreasen
2022-03-29 23:54:43 +02:00
committed by Stephan Brandauer
parent 0db7c39c34
commit dbc89fd9ab

View File

@@ -376,26 +376,31 @@ private module SyntacticUtilities {
}
string getSimpleAccessPath(DataFlow::Node node) {
result = node.asExpr().(VarAccess).getName()
or
exists(DataFlow::PropRead p |
p = node and
result = getSimpleAccessPath(p.getBase()) + "." + p.getPropertyName()
)
or
exists(DataFlow::MethodCallNode p |
p = node and
result = getSimpleAccessPath(p.getReceiver()) + "." + p.getMethodName() + "()"
)
or
exists(DataFlow::CallNode p |
p = node and
not p instanceof DataFlow::MethodCallNode and
result = p.getCalleeName() + "()"
)
if node.asExpr() instanceof SuperAccess
then result = "super"
else
if node.asExpr() instanceof ThisAccess
then result = "this"
else
if node.asExpr() instanceof VarAccess
then result = node.asExpr().(VarAccess).getName()
else
if node instanceof DataFlow::PropRead
then
result =
getSimpleAccessPath(node.(DataFlow::PropRead).getBase()) + "." +
getPropertyNameOrUnknown(node)
else
if node instanceof DataFlow::InvokeNode
then result = getSimpleAccessPath(node.(DataFlow::InvokeNode).getCalleeNode()) + "()"
else result = "?"
}
}
string getPropertyNameOrUnknown(DataFlow::PropRead read) {
if exists(read.getPropertyName()) then result = read.getPropertyName() else result = "?"
}
class CalleeAccessPathSimpleFromArgumentTraversal extends EndPointFeature,
TCalleeAccessPathSimpleFromArgumentTraversal {
override string getEncoding() { result = "calleeAccessPathSimpleFromArgumentTraversal" }