Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control Flow Analysis Visualization: Result generated by CodeQL can not understand well by human #16920

Open
zouyi73 opened this issue Jul 8, 2024 · 2 comments
Labels
question Further information is requested

Comments

@zouyi73
Copy link

zouyi73 commented Jul 8, 2024

CFA(Control Flow Analysis)
I used the following simple QL statement:

/**
 * @name Control Flow Graph Visualization
 * @description This query identifies control flow nodes within a function and visualizes the control flow graph, helping to understand the flow of execution.
 * @kind graph
 * @id cpp/control-flow-graph-visualization
 * @problem.severity recommendation
 * @tags control-flow analysis
 * @precision high
 * @security-severity 0.0
 */

import cpp
import semmle.code.cpp.controlflow.internal.CFG

from Function f, ControlFlowNode start, ControlFlowNode end, Stmt s1, Stmt s2
where
  start.getControlFlowScope() = f and
  end.getControlFlowScope() = f and
  start.getASuccessor() = end and
  f.getFile().getBaseName() = "ip_output.c" and
  f.getName() = "__ip_append_data"
select
  start,
  end,
  "This is a control flow from " + start.getEnclosingStmt().toString() + " to " + end.getEnclosingStmt().toString() + " in function " + 

 f.getQualifiedName()

Although I output the control flow of a specific function in formats such as SARIF, DOT, and DGML, the results are not easily understandable by humans. I want to ask if CodeQL provides any other methods for visualizing control flow that can be easily understood by both humans and, if possible, LLMs (large language models).

@zouyi73 zouyi73 added the question Further information is requested label Jul 8, 2024
@zouyi73
Copy link
Author

zouyi73 commented Jul 8, 2024

And I find that the .dot file could tranfer to .png file, but the query I write seems not to work.

@ginsbach
Copy link
Contributor

ginsbach commented Jul 9, 2024

Thank you for the question!

CodeQL does not have functionality built in to visualize the graphs. Instead, we recommend generating files in standard formats (e.g. DOT, DGML, as you mentioned above) and then relying on other tools to consume them. Compatible graph viewers are available as VSCode plugins, among others.

LLMs should do ok when given SARIF files with the schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants