Skip to content

Commit 27646ce

Browse files
authored
Merge pull request github#14547 from owen-mc/go/enable-data-flow-consistency-checks
Go: make data flow consistency checks available (and fix some)
2 parents a3d53ba + 0ba0063 commit 27646ce

File tree

6 files changed

+40
-2
lines changed

6 files changed

+40
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import semmle.go.dataflow.internal.DataFlowImplConsistency::Consistency

go/ql/consistency-queries/qlpack.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: codeql-go-consistency-queries
2+
version: 0.0.0
3+
groups:
4+
- go
5+
- queries
6+
extractor: go
7+
dependencies:
8+
codeql/go-all: ${workspace}
9+
warnOnImplicitThis: true
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: fix
3+
---
4+
* 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.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Provides consistency queries for checking invariants in the language-specific
3+
* data-flow classes and predicates.
4+
*/
5+
6+
private import go
7+
private import DataFlowImplSpecific
8+
private import TaintTrackingImplSpecific
9+
private import codeql.dataflow.internal.DataFlowImplConsistency
10+
11+
private module Input implements InputSig<GoDataFlow> { }
12+
13+
module Consistency = MakeConsistency<GoDataFlow, GoTaintTracking, Input>;

go/ql/lib/semmle/go/dataflow/internal/DataFlowNodes.qll

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ module Private {
2121
DataFlowCallable nodeGetEnclosingCallable(Node n) {
2222
result.asCallable() = n.getEnclosingCallable()
2323
or
24-
(n = MkInstructionNode(_) or n = MkSsaNode(_) or n = MkGlobalFunctionNode(_)) and
24+
not n instanceof FlowSummaryNode and
2525
not exists(n.getEnclosingCallable()) and
26-
result.asFileScope() = n.getFile()
26+
(
27+
result.asFileScope() = n.getFile()
28+
or
29+
not exists(n.getFile()) and
30+
result.isExternalFileScope()
31+
)
2732
or
2833
result.asSummarizedCallable() = n.(FlowSummaryNode).getSummarizedCallable()
2934
}

go/ql/lib/semmle/go/dataflow/internal/DataFlowPrivate.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ class DataFlowLocation = Location;
256256
private newtype TDataFlowCallable =
257257
TCallable(Callable c) or
258258
TFileScope(File f) or
259+
TExternalFileScope() or
259260
TSummarizedCallable(FlowSummary::SummarizedCallable c)
260261

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

273+
/**
274+
* Holds if this `DataFlowCallable` is an external file scope.
275+
*/
276+
predicate isExternalFileScope() { this = TExternalFileScope() }
277+
272278
/**
273279
* Gets the `SummarizedCallable` corresponding to this `DataFlowCallable`, if any.
274280
*/

0 commit comments

Comments
 (0)