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

Go: make data flow consistency checks available (and fix one) #14547

Merged
merged 7 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go/ql/consistency-queries/DataFlowConsistency.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import semmle.go.dataflow.internal.DataFlowImplConsistency::Consistency
9 changes: 9 additions & 0 deletions go/ql/consistency-queries/qlpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: codeql-go-consistency-queries
version: 0.0.0
groups:
- go
- queries
extractor: go
dependencies:
codeql/go-all: ${workspace}
warnOnImplicitThis: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: fix
---
* Fixed a bug where data flow nodes in files that are not in the project being analyzed (such as libraries) and are not contained within a function were not given an enclosing `Callable`. Note that for nodes that are not contained within a function, the enclosing callable is considered to be the file itself. This may cause some minor changes to results.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Provides consistency queries for checking invariants in the language-specific
* data-flow classes and predicates.
*/

private import go
private import DataFlowImplSpecific
private import TaintTrackingImplSpecific
private import codeql.dataflow.internal.DataFlowImplConsistency

private module Input implements InputSig<GoDataFlow> { }

module Consistency = MakeConsistency<GoDataFlow, GoTaintTracking, Input>;
9 changes: 7 additions & 2 deletions go/ql/lib/semmle/go/dataflow/internal/DataFlowNodes.qll
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ module Private {
DataFlowCallable nodeGetEnclosingCallable(Node n) {
result.asCallable() = n.getEnclosingCallable()
or
(n = MkInstructionNode(_) or n = MkSsaNode(_) or n = MkGlobalFunctionNode(_)) and
not n instanceof FlowSummaryNode and
owen-mc marked this conversation as resolved.
Show resolved Hide resolved
not exists(n.getEnclosingCallable()) and
result.asFileScope() = n.getFile()
(
result.asFileScope() = n.getFile()
or
not exists(n.getFile()) and
result.isExternalFileScope()
)
or
result.asSummarizedCallable() = n.(FlowSummaryNode).getSummarizedCallable()
}
Expand Down
6 changes: 6 additions & 0 deletions go/ql/lib/semmle/go/dataflow/internal/DataFlowPrivate.qll
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ class DataFlowLocation = Location;
private newtype TDataFlowCallable =
TCallable(Callable c) or
TFileScope(File f) or
TExternalFileScope() or
TSummarizedCallable(FlowSummary::SummarizedCallable c)

class DataFlowCallable extends TDataFlowCallable {
Expand All @@ -269,6 +270,11 @@ class DataFlowCallable extends TDataFlowCallable {
*/
File asFileScope() { this = TFileScope(result) }

/**
* Holds if this `DataFlowCallable` is an external file scope.
*/
predicate isExternalFileScope() { this = TExternalFileScope() }

/**
* Gets the `SummarizedCallable` corresponding to this `DataFlowCallable`, if any.
*/
Expand Down
Loading