Is there a way to get path analysis for custom nodes and edges? #12327
-
I am trying to understand how to define my own nodes and edges predicate to run the flow analysis. I found this part of the documentation suggesting that it is possible. Is it only possible for When doing so, and defining What am I misunderstanding here? Adding my whole query below:/**
* @name experiment
* @description experiment
* @kind path-problem
*/
import go
import semmle.go.dataflow.DataFlow
// the class that I am using for defining edges relation
class ExtendedCallNode extends DataFlow::CallNode, DataFlow::Node {
ExtendedCallNode() {
this instanceof DataFlow::CallNode
}
DataFlow::CallNode getParentCallNode (){
exists(
Function f |
this.getTarget() = f
and
result = this.asExpr().getEnclosingFunction().getACall()
)
}
}
class MyDataFlowConfiguration extends DataFlow::Configuration {
MyDataFlowConfiguration() { this = "MyDataFlowConfiguration" }
override predicate isSource(DataFlow::Node source) {
source instanceof ExtendedCallNode
and
source.asExpr().(CallExpr).getTarget().mustPanic()
}
override predicate isSink(DataFlow::Node sink) {
sink instanceof ExtendedCallNode
}
}
query predicate edges(DataFlow::Node a, DataFlow::Node b) {
a instanceof ExtendedCallNode
and
b instanceof ExtendedCallNode
and
a.(ExtendedCallNode).getParentCallNode() = b
}
query predicate nodes(DataFlow::Node a){
a instanceof ExtendedCallNode
}
from MyDataFlowConfiguration cfg, DataFlow::Node source, DataFlow::Node sink
where cfg.hasFlow(source, sink)
select source, source, sink, "path flow" |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
If you're rolling your own analysis from scratch, and not looking to reuse any of the existing dataflow infrastructure, then you don't need to use any particular type for your nodes, as long as the types of your Thus, the type could be just your own But the real problem you're facing is probably the "alert interpretation" computation that runs after the raw QL evaluation. It expects that the It is probably not the case that the nodes that match the If you build your own graph by defining your own In this case it looks like what you'd really like to say would be something like from MyFlowConfiguration cfg, ExtendedCallNode source, ExtendedCallNode sink
where edges*(source, sink) and cfg.isSource(source) and cfg.isSink(sink)
select source, source, sink, "path flow" Something like that is what the You could even use |
Beta Was this translation helpful? Give feedback.
-
Do you want to visualize the control flow graph and find all paths from a given source method to a target method? If so, you can port my answer for Java to Go: Hope this helps. |
Beta Was this translation helpful? Give feedback.
If you're rolling your own analysis from scratch, and not looking to reuse any of the existing dataflow infrastructure, then you don't need to use any particular type for your nodes, as long as the types of your
nodes
andedges
predicates match the second and third columns of theselect
result. For the best result display, your node type should have agetLocation()
member predicate.Thus, the type could be just your own
ExtendedCallNode
type.But the real problem you're facing is probably the "alert interpretation" computation that runs after the raw QL evaluation. It expects that the
source
andsink
columns of yourselect
output are actually the ends of a path in the graph defined by your…