Using CodeQL for Data Flow Analysis and Visualization #15982
Replies: 3 comments 9 replies
-
Do you care about interprocedural flows, or only within a single procedure? |
Beta Was this translation helpful? Give feedback.
-
This helped a lot, thanks! |
Beta Was this translation helpful? Give feedback.
-
Try this: Now for whatever reason while So without /**
* @kind path-problem
*/
import cpp
import semmle.code.cpp.dataflow.new.TaintTracking
module StructDataFlowConfiguration implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) {
exists(Function fxn, Parameter p |
// scope to function
fxn.getName() = "github_discussion_example" and
// scope to parameter within function
p.getFunction() = fxn and
p.getName() = "status" and
p = source.asParameter()
)
}
predicate isSink(DataFlow::Node sink) {
exists(IfStmt is | is.getCondition().getAChild*() = sink.asExpr())
}
predicate isAdditionalFlowStep(DataFlow::Node n1, DataFlow::Node n2) {
exists(FieldAccess fa |
n1.asIndirectExpr() = fa.getQualifier() and
n2.asExpr() = fa and
fa.getQualifier().getType().(UserType).hasQualifiedName("", "status_msg_t")
)
}
}
module Flows = DataFlow::Global<StructDataFlowConfiguration>;
import Flows::PathGraph
from Flows::PathNode source, Flows::PathNode sink
where Flows::flowPath(source, sink)
select sink.getNode(), source, sink, "This node receives flow from $@.", source.getNode(),
"this source" |
Beta Was this translation helpful? Give feedback.
-
Background
My team and I have been experimenting with CodeQL for some time, and we need some guidance on filtering CodeQL's data flow analysis results and on using the graph making capabilities.
Below is the query we have come up with. It traces flow from a function parameter and its fields to any sink:
Here is some minimal code that you can run the query on to produce results.
Issues
status.status
and end atif (! status_bit) return;
In addition, there are multiple flows that start and end atif (! tx_bit) return;
There are many more such examples. How can we refine this query to reduce/eliminate duplicates?status
parameter ->status_bit
->if
conditionstatus
parameter ->tx_bit
->if
condition@kind graph
query and then view the output as a visual graph (perhaps use bqrs interpret to convert the raw query output to adot
file). How can we go about doing this? We have seen How to use @kind graph query? #7437, but were not able to make much sense of it and documentation is scarce.Thanks!
Beta Was this translation helpful? Give feedback.
All reactions