Skip to content

Conversation

@MathiasVP
Copy link
Collaborator

@MathiasVP MathiasVP commented May 19, 2025

This PR does what it says on the (very long) tin 😅

In #149 we added a "shared" global control-flow library. However, at the time I didn't want to introduce a Microsoft-specific shared library into the shared folder because I wasn't aware if this was something we wanted to do. However, I have since learned that we've already done this for our dataflowstack library.

So this PR does two things:

  • It converts the "shared" global control-flow library into a properly shared library
  • It instantiates the library for C#

This is motivated by an internal ask where global control-flow was needed in C#.

Example usage in C#:

/**
 * @kind path-problem
 */

import csharp as CS
import semmle.code.csharp.interproccontrolflow.ControlFlow
import Flow::PathGraph

module Config implements ControlFlow::ConfigSig {
  predicate isSource(ControlFlow::Node source) {
    // Start at the entry for a method called `A`
    source.(CS::ControlFlow::Nodes::EntryNode).getCallable().hasName("A")
  }

  predicate isSink(ControlFlow::Node sink) {
    // And end at an entry to a method called `B`
    sink.(CS::ControlFlow::Nodes::EntryNode).getEnclosingCallable().hasName("B")
  }
}

module Flow = ControlFlow::Global<Config>;

from Flow::PathNode source, Flow::PathNode sink
where Flow::flowPath(source, sink)
select sink.getNode(), source, sink, ""

Note that I had to import csharp using a qualified import since csharp already exports a module called ControlFlow 😭 Oh well...

@MathiasVP MathiasVP merged commit 2f0b064 into main May 19, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants