Skip to content

Commit f9dbf67

Browse files
committed
Java: Use FlowSummaryImpl from dataflow pack
1 parent 2d3f96f commit f9dbf67

File tree

14 files changed

+398
-2065
lines changed

14 files changed

+398
-2065
lines changed

java/ql/lib/semmle/code/java/dataflow/ExternalFlow.qll

+69-5
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,13 @@
8989

9090
import java
9191
private import semmle.code.java.dataflow.DataFlow::DataFlow
92+
private import FlowSummary as FlowSummary
9293
private import internal.DataFlowPrivate
94+
private import internal.FlowSummaryImpl
95+
private import internal.FlowSummaryImpl::Public
96+
private import internal.FlowSummaryImpl::Private
9397
private import internal.FlowSummaryImpl::Private::External
94-
private import internal.FlowSummaryImplSpecific as FlowSummaryImplSpecific
95-
private import internal.AccessPathSyntax
9698
private import internal.ExternalFlowExtensions as Extensions
97-
private import FlowSummary
9899
private import codeql.mad.ModelValidation as SharedModelVal
99100

100101
/**
@@ -234,6 +235,21 @@ predicate modelCoverage(string package, int pkgs, string kind, string part, int
234235

235236
/** Provides a query predicate to check the MaD models for validation errors. */
236237
module ModelValidation {
238+
private import codeql.dataflow.internal.AccessPathSyntax as AccessPathSyntax
239+
240+
private predicate getRelevantAccessPath(string path) {
241+
summaryModel(_, _, _, _, _, _, path, _, _, _) or
242+
summaryModel(_, _, _, _, _, _, _, path, _, _) or
243+
sinkModel(_, _, _, _, _, _, path, _, _) or
244+
sourceModel(_, _, _, _, _, _, path, _, _)
245+
}
246+
247+
private module MkAccessPath = AccessPathSyntax::AccessPath<getRelevantAccessPath/1>;
248+
249+
class AccessPath = MkAccessPath::AccessPath;
250+
251+
class AccessPathToken = MkAccessPath::AccessPathToken;
252+
237253
private string getInvalidModelInput() {
238254
exists(string pred, AccessPath input, AccessPathToken part |
239255
sinkModel(_, _, _, _, _, _, input, _, _) and pred = "sink"
@@ -478,7 +494,9 @@ private module Cached {
478494
*/
479495
cached
480496
predicate sourceNode(Node node, string kind) {
481-
exists(FlowSummaryImplSpecific::InterpretNode n | isSourceNode(n, kind) and n.asNode() = node)
497+
exists(SourceSinkInterpretationInput::InterpretNode n |
498+
isSourceNode(n, kind) and n.asNode() = node
499+
)
482500
}
483501

484502
/**
@@ -487,8 +505,54 @@ private module Cached {
487505
*/
488506
cached
489507
predicate sinkNode(Node node, string kind) {
490-
exists(FlowSummaryImplSpecific::InterpretNode n | isSinkNode(n, kind) and n.asNode() = node)
508+
exists(SourceSinkInterpretationInput::InterpretNode n |
509+
isSinkNode(n, kind) and n.asNode() = node
510+
)
491511
}
492512
}
493513

494514
import Cached
515+
516+
private class SummarizedCallableAdapter extends SummarizedCallable {
517+
SummarizedCallableAdapter() { summaryElement(this, _, _, _, _) }
518+
519+
private predicate relevantSummaryElementManual(string input, string output, string kind) {
520+
exists(Provenance provenance |
521+
summaryElement(this, input, output, kind, provenance) and
522+
provenance.isManual()
523+
)
524+
}
525+
526+
private predicate relevantSummaryElementGenerated(string input, string output, string kind) {
527+
exists(Provenance provenance |
528+
summaryElement(this, input, output, kind, provenance) and
529+
provenance.isGenerated()
530+
)
531+
}
532+
533+
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
534+
exists(string kind |
535+
this.relevantSummaryElementManual(input, output, kind)
536+
or
537+
not this.relevantSummaryElementManual(_, _, _) and
538+
this.relevantSummaryElementGenerated(input, output, kind)
539+
|
540+
if kind = "value" then preservesValue = true else preservesValue = false
541+
)
542+
}
543+
544+
override predicate hasProvenance(Provenance provenance) {
545+
summaryElement(this, _, _, _, provenance)
546+
}
547+
}
548+
549+
private class NeutralCallableAdapter extends NeutralCallable {
550+
string kind;
551+
string provenance_;
552+
553+
NeutralCallableAdapter() { neutralElement(this, kind, provenance_) }
554+
555+
override string getKind() { result = kind }
556+
557+
override predicate hasProvenance(Provenance provenance) { provenance = provenance_ }
558+
}

java/ql/lib/semmle/code/java/dataflow/FlowSummary.qll

+7-63
Original file line numberDiff line numberDiff line change
@@ -6,63 +6,13 @@ import java
66
private import internal.FlowSummaryImpl as Impl
77
private import internal.DataFlowUtil
88

9-
class SummaryComponent = Impl::Public::SummaryComponent;
9+
deprecated class SummaryComponent = Impl::Private::SummaryComponent;
1010

11-
/** Provides predicates for constructing summary components. */
12-
module SummaryComponent {
13-
import Impl::Public::SummaryComponent
11+
deprecated module SummaryComponent = Impl::Private::SummaryComponent;
1412

15-
/** Gets a summary component that represents a qualifier. */
16-
SummaryComponent qualifier() { result = argument(-1) }
13+
deprecated class SummaryComponentStack = Impl::Private::SummaryComponentStack;
1714

18-
/** Gets a summary component for field `f`. */
19-
SummaryComponent field(Field f) { result = content(any(FieldContent c | c.getField() = f)) }
20-
21-
/** Gets a summary component for `Element`. */
22-
SummaryComponent element() { result = content(any(CollectionContent c)) }
23-
24-
/** Gets a summary component for `ArrayElement`. */
25-
SummaryComponent arrayElement() { result = content(any(ArrayContent c)) }
26-
27-
/** Gets a summary component for `MapValue`. */
28-
SummaryComponent mapValue() { result = content(any(MapValueContent c)) }
29-
30-
/** Gets a summary component that represents the return value of a call. */
31-
SummaryComponent return() { result = return(_) }
32-
}
33-
34-
class SummaryComponentStack = Impl::Public::SummaryComponentStack;
35-
36-
/** Provides predicates for constructing stacks of summary components. */
37-
module SummaryComponentStack {
38-
import Impl::Public::SummaryComponentStack
39-
40-
/** Gets a singleton stack representing a qualifier. */
41-
SummaryComponentStack qualifier() { result = singleton(SummaryComponent::qualifier()) }
42-
43-
/** Gets a stack representing a field `f` of `object`. */
44-
SummaryComponentStack fieldOf(Field f, SummaryComponentStack object) {
45-
result = push(SummaryComponent::field(f), object)
46-
}
47-
48-
/** Gets a stack representing `Element` of `object`. */
49-
SummaryComponentStack elementOf(SummaryComponentStack object) {
50-
result = push(SummaryComponent::element(), object)
51-
}
52-
53-
/** Gets a stack representing `ArrayElement` of `object`. */
54-
SummaryComponentStack arrayElementOf(SummaryComponentStack object) {
55-
result = push(SummaryComponent::arrayElement(), object)
56-
}
57-
58-
/** Gets a stack representing `MapValue` of `object`. */
59-
SummaryComponentStack mapValueOf(SummaryComponentStack object) {
60-
result = push(SummaryComponent::mapValue(), object)
61-
}
62-
63-
/** Gets a singleton stack representing a (normal) return. */
64-
SummaryComponentStack return() { result = singleton(SummaryComponent::return()) }
65-
}
15+
deprecated module SummaryComponentStack = Impl::Private::SummaryComponentStack;
6616

6717
/** A synthetic callable with a set of concrete call sites and a flow summary. */
6818
abstract class SyntheticCallable extends string {
@@ -77,11 +27,7 @@ abstract class SyntheticCallable extends string {
7727
*
7828
* See `SummarizedCallable::propagatesFlow` for details.
7929
*/
80-
predicate propagatesFlow(
81-
SummaryComponentStack input, SummaryComponentStack output, boolean preservesValue
82-
) {
83-
none()
84-
}
30+
abstract predicate propagatesFlow(string input, string output, boolean preservesValue);
8531

8632
/**
8733
* Gets the type of the parameter at the specified position with -1 indicating
@@ -180,11 +126,9 @@ class SummarizedCallable = Impl::Public::SummarizedCallable;
180126
* to `SummarizedCallable`.
181127
*/
182128
private class SummarizedSyntheticCallableAdapter extends SummarizedCallable, TSyntheticCallable {
183-
override predicate propagatesFlow(
184-
SummaryComponentStack input, SummaryComponentStack output, boolean preservesValue
185-
) {
129+
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
186130
this.asSyntheticCallable().propagatesFlow(input, output, preservesValue)
187131
}
188132
}
189133

190-
class RequiredSummaryComponentStack = Impl::Public::RequiredSummaryComponentStack;
134+
deprecated class RequiredSummaryComponentStack = Impl::Private::RequiredSummaryComponentStack;

java/ql/lib/semmle/code/java/dataflow/internal/AccessPathSyntax.qll

-182
This file was deleted.

0 commit comments

Comments
 (0)