Skip to content

Commit b160f27

Browse files
authored
Merge branch 'main' into codex/issue-5163-wikimedia-links
2 parents c8afb1d + daa37c0 commit b160f27

126 files changed

Lines changed: 13029 additions & 13675 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

BUILD.bazel

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,11 @@ exports_files([
33
"Cargo.lock",
44
"Cargo.toml",
55
])
6+
7+
constraint_setting(name = "swift_runtime_linkage")
8+
9+
constraint_value(
10+
name = "static_swift_runtime",
11+
constraint_setting = ":swift_runtime_linkage",
12+
visibility = ["//visibility:public"],
13+
)

MODULE.bazel

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ bazel_dep(name = "gazelle", version = "0.50.0")
3131
bazel_dep(name = "rules_dotnet", version = "0.21.5-codeql.1")
3232
bazel_dep(name = "googletest", version = "1.17.0.bcr.2")
3333
bazel_dep(name = "rules_rust", version = "0.69.0")
34-
bazel_dep(name = "rules_swift", version = "4.0.0-rc5-codeql.1")
34+
bazel_dep(name = "rules_swift", version = "4.0.0-rc5-codeql.2")
3535
bazel_dep(name = "swift-syntax", version = "603.0.2")
3636
bazel_dep(name = "zstd", version = "1.5.7.bcr.1")
3737

@@ -228,7 +228,7 @@ use_repo(
228228
# `unified/swift-syntax-rs` package is not loadable in that context. Keep this
229229
# in sync with `unified/swift-syntax-rs/.swift-version` (used by the `cargo`
230230
# build) and the `swift-syntax` release in `swift/Package.swift`.
231-
swift = use_extension("@rules_swift//swift:extensions.bzl", "swift")
231+
swift = use_extension("@rules_swift//swift:extensions.bzl", "swift", dev_dependency = True)
232232
swift.toolchain(
233233
name = "swift_toolchain",
234234
swift_version = "6.3.3",
@@ -243,6 +243,7 @@ use_repo(
243243
register_toolchains(
244244
"@swift_toolchain//:swift_toolchain_exec_ubuntu22.04",
245245
"@swift_toolchain//:swift_toolchain_exec_xcode",
246+
dev_dependency = True,
246247
)
247248

248249
node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: feature
3+
---
4+
* Sources and sinks defined using models-as-data now support access paths with fields. For example, the path `ReturnValue.Field[S::f]` makes the field `S::f` a flow source when it is returned by a call.

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
import cpp
114114
private import new.DataFlow
115115
private import semmle.code.cpp.controlflow.IRGuards
116+
private import semmle.code.cpp.ir.dataflow.internal.DataFlowNodes as Nodes
116117
private import semmle.code.cpp.ir.dataflow.internal.DataFlowPrivate as Private
117118
private import semmle.code.cpp.ir.dataflow.internal.DataFlowUtil
118119
private import internal.FlowSummaryImpl
@@ -952,9 +953,7 @@ private module Cached {
952953
*/
953954
cached
954955
predicate sourceNode(DataFlow::Node node, string kind, string model) {
955-
exists(SourceSinkInterpretationInput::InterpretNode n |
956-
isSourceNode(n, kind, model) and n.asNode() = node
957-
)
956+
node.(Nodes::FlowSummaryNode).isSource(kind, model)
958957
}
959958

960959
/**
@@ -963,9 +962,7 @@ private module Cached {
963962
*/
964963
cached
965964
predicate sinkNode(DataFlow::Node node, string kind, string model) {
966-
exists(SourceSinkInterpretationInput::InterpretNode n |
967-
isSinkNode(n, kind, model) and n.asNode() = node
968-
)
965+
node.(Nodes::FlowSummaryNode).isSink(kind, model)
969966
}
970967

971968
private newtype TKindModelPair =

cpp/ql/lib/semmle/code/cpp/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 221 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ module Input implements InputSig<Location, DataFlowImplSpecific::CppDataFlow> {
1717

1818
class SummarizedCallableBase = Function;
1919

20-
class SourceBase extends Void {
21-
Location getLocation() { none() }
22-
}
20+
class SourceBase = Function;
2321

24-
class SinkBase = SourceBase;
22+
class SinkBase = Function;
2523

2624
class FlowSummaryCallBase = CallInstruction;
2725

@@ -134,15 +132,192 @@ module Input implements InputSig<Location, DataFlowImplSpecific::CppDataFlow> {
134132

135133
private import Make<Location, DataFlowImplSpecific::CppDataFlow, Input> as Impl
136134

135+
private class ConversionCall extends Call {
136+
ConversionCall() { this.getTarget() instanceof ConversionOperator }
137+
}
138+
137139
private module Input2 implements Impl::Private::InputSig2 {
138140
private import codeql.util.Void
139141

140-
class SourceSinkReportingElement extends Void {
141-
Location getLocation() { none() }
142+
pragma[nomagic]
143+
private predicate hasFunctionAndIndirectionIndex(
144+
Function f, int indirectionIndex, Ssa::ExplicitDefinition def
145+
) {
146+
def.getFunction() = f and
147+
def.getSourceVariable().getIRVariable() instanceof IRReturnVariable and
148+
def.getIndirectionIndex() = indirectionIndex
149+
}
150+
151+
/** Holds if `def` defines `e` as a returned value with return kind `rk`. */
152+
bindingset[rk, e]
153+
private predicate isReturnExpr(Function f, ReturnKind rk, Expr e) {
154+
exists(Ssa::ExplicitDefinition def |
155+
hasFunctionAndIndirectionIndex(f, rk.getIndirectionIndex(), def) and
156+
e =
157+
def.getAssignedInstruction()
158+
.(StoreInstruction)
159+
.getSourceValue()
160+
.getUnconvertedResultExpression()
161+
)
162+
}
163+
164+
private MemberFunction getFunctionFromType(Expr e) {
165+
result.getClassAndName("operator()").getADerivedClass*() = e.getUnspecifiedType()
166+
}
167+
168+
private Function getFunctionFromExpr(Expr e) {
169+
result = e.(FunctionAccess).getTarget()
170+
or
171+
result = e.(ConversionCall).getQualifier().(LambdaExpression).getLambdaFunction()
172+
}
173+
174+
class SourceSinkReportingElement extends Element {
175+
SourceSinkReportingElement() { this instanceof Expr or this instanceof Parameter }
176+
177+
DataFlowCallable getEnclosingCallable() {
178+
result.asSourceCallable() =
179+
[this.(Expr).getEnclosingFunction(), this.(Parameter).getFunction()]
180+
}
181+
182+
/** Gets the function invoked when this element is used as a callback. */
183+
private Function getCallable() {
184+
// The expression is a struct which implements `operator()`.
185+
result = getFunctionFromType(this)
186+
or
187+
// The expression is a function pointer
188+
result = getFunctionFromExpr(this)
189+
or
190+
// The expression is an SSA read of an assignment of a callable
191+
exists(Ssa::Definition def |
192+
def.getAUse().getDef().getUnconvertedResultExpression() = this and
193+
result =
194+
getFunctionFromExpr(def.getAnUltimateDefinition()
195+
.(Ssa::DirectExplicitDefinition)
196+
.getAssignedInstruction()
197+
.(StoreInstruction)
198+
.getSourceValue()
199+
.getUnconvertedResultExpression())
200+
)
201+
}
202+
203+
SourceSinkReportingElement getASuccessor(Impl::Private::SummaryComponent sc) {
204+
exists(Function f | f = this.getCallable() |
205+
exists(ParameterPosition pos | sc = Impl::Private::SummaryComponent::parameter(pos) |
206+
result = pos.getParameter(f)
207+
)
208+
or
209+
exists(ReturnKind rk |
210+
sc = Impl::Private::SummaryComponent::return(rk) and
211+
isReturnExpr(f, rk, result)
212+
)
213+
)
214+
}
215+
}
216+
217+
bindingset[source, sc]
218+
SourceSinkReportingElement getASourceReportingElement(
219+
Input::SourceBase source, Impl::Private::SummaryComponent sc
220+
) {
221+
exists(Call call | call.getTarget() = source |
222+
sc = Impl::Private::SummaryComponent::return(_) and
223+
result = call
224+
or
225+
exists(ArgumentPosition pos |
226+
sc = Impl::Private::SummaryComponent::argument(pos) and
227+
result = pos.getArgument(call)
228+
)
229+
)
230+
or
231+
exists(ParameterPosition pos |
232+
sc = Impl::Private::SummaryComponent::parameter(pos) and
233+
result = pos.getParameter(source)
234+
)
235+
}
236+
237+
pragma[nomagic]
238+
private IndirectReturnOutNode getIndirectReturn(CallInstruction call, NormalReturnKind rk) {
239+
result.getCallInstruction() = call and
240+
pragma[only_bind_out](result.getIndirectionIndex()) =
241+
pragma[only_bind_out](rk.getIndirectionIndex())
242+
}
243+
244+
pragma[nomagic]
245+
private predicate hasKindAndEnclosingFunction(Function f, ReturnKind rk, ReturnNode r) {
246+
r.getEnclosingCallable().asSourceCallable() = f and
247+
r.getKind() = rk
248+
}
142249

143-
DataFlowCallable getEnclosingCallable() { none() }
250+
pragma[nomagic]
251+
private predicate hasParameterAndIndirectionIndex(
252+
Parameter p, int indirectionIndex, ParameterNode n
253+
) {
254+
n.getParameter() = p and
255+
n.getIndirectionIndex() = indirectionIndex
256+
}
144257

145-
SourceSinkReportingElement getASuccessor(Impl::Private::SummaryComponent sc) { none() }
258+
bindingset[e, sc]
259+
Node getSourceDataFlowNode(SourceSinkReportingElement e, Impl::Private::SummaryComponent sc) {
260+
exists(DataFlowCall call |
261+
exists(ArgumentPosition pos |
262+
sc = Impl::Private::SummaryComponent::argument(pos) and
263+
pos.getArgument(call.asCallInstruction().getUnconvertedResultExpression()) = e
264+
|
265+
pos.getIndirectionIndex() = 0 and
266+
result.(PostUpdateNode).getPreUpdateNode().asExpr() = e
267+
or
268+
result.(PostUpdateNode).getPreUpdateNode().asIndirectExpr(pos.getIndirectionIndex()) = e
269+
)
270+
or
271+
exists(ReturnKind rk |
272+
sc = Impl::Private::SummaryComponent::return(rk) and
273+
// When `e` is a call the node becomes an `OutNode`.
274+
e = call.asCallInstruction().getUnconvertedResultExpression()
275+
|
276+
rk.getIndirectionIndex() = 0 and
277+
simpleOutNode(result, call.asCallInstruction())
278+
or
279+
result = getIndirectReturn(call.asCallInstruction(), rk)
280+
)
281+
)
282+
or
283+
exists(ParameterPosition pos |
284+
sc = Impl::Private::SummaryComponent::parameter(pos) and
285+
hasParameterAndIndirectionIndex(e, pos.getIndirectionIndex(), result)
286+
)
287+
or
288+
exists(Function f, ReturnKind rk |
289+
sc = Impl::Private::SummaryComponent::return(rk) and
290+
// When `e` is the returned expression from a function the node is
291+
// the `ReturnNode`.
292+
isReturnExpr(f, rk, e) and
293+
hasKindAndEnclosingFunction(f, rk, result)
294+
)
295+
}
296+
297+
bindingset[sink, sc]
298+
SourceSinkReportingElement getASinkReportingElement(
299+
Input::SinkBase sink, Impl::Private::SummaryComponent sc
300+
) {
301+
exists(Call call, ArgumentPosition pos |
302+
call.getTarget() = sink and
303+
sc = Impl::Private::SummaryComponent::argument(pos) and
304+
result = pos.getArgument(call)
305+
)
306+
}
307+
308+
bindingset[e, sc]
309+
Node getSinkDataFlowNode(SourceSinkReportingElement e, Impl::Private::SummaryComponent sc) {
310+
exists(ArgumentPosition pos, CallInstruction call |
311+
sc = Impl::Private::SummaryComponent::argument(pos) and
312+
pos.getArgument(call.getUnconvertedResultExpression()) = e and
313+
result.(ArgumentNode).sourceArgumentOf(call, pos)
314+
)
315+
or
316+
exists(Function f, ReturnKind rk |
317+
sc = Impl::Private::SummaryComponent::return(rk) and
318+
isReturnExpr(f, rk, e) and
319+
hasKindAndEnclosingFunction(f, rk, result)
320+
)
146321
}
147322
}
148323

@@ -319,3 +494,41 @@ module Private {
319494
}
320495

321496
module Public = Impl::Public;
497+
498+
private class SourceModelFunction extends Public::SourceElement instanceof Function {
499+
private string namespace;
500+
private string type;
501+
private boolean subtypes;
502+
private string name;
503+
private string signature;
504+
private string ext;
505+
506+
SourceModelFunction() {
507+
sourceModel(namespace, type, subtypes, name, signature, ext, _, _, _, _) and
508+
this = interpretElement(namespace, type, subtypes, name, signature, ext)
509+
}
510+
511+
override predicate isSource(
512+
string output, string kind, Public::Provenance provenance, string model
513+
) {
514+
sourceModel(namespace, type, subtypes, name, signature, ext, output, kind, provenance, model)
515+
}
516+
}
517+
518+
private class SinkModelFunction extends Public::SinkElement instanceof Function {
519+
private string namespace;
520+
private string type;
521+
private boolean subtypes;
522+
private string name;
523+
private string signature;
524+
private string ext;
525+
526+
SinkModelFunction() {
527+
sinkModel(namespace, type, subtypes, name, signature, ext, _, _, _, _) and
528+
this = interpretElement(namespace, type, subtypes, name, signature, ext)
529+
}
530+
531+
override predicate isSink(string input, string kind, Public::Provenance provenance, string model) {
532+
sinkModel(namespace, type, subtypes, name, signature, ext, input, kind, provenance, model)
533+
}
534+
}

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowImplConsistency.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
private import cpp
77
private import DataFlowImplSpecific
88
private import TaintTrackingImplSpecific
9+
private import DataFlowNodes as Nodes
10+
private import semmle.code.cpp.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
911
private import codeql.dataflow.internal.DataFlowImplConsistency
1012

1113
private module Input implements InputSig<Location, CppDataFlow> {
@@ -14,6 +16,12 @@ private module Input implements InputSig<Location, CppDataFlow> {
1416
// complex to model here.
1517
any()
1618
}
19+
20+
predicate postWithInFlowExclude(CppDataFlow::Node n) {
21+
n instanceof Nodes::FlowSummaryNode
22+
or
23+
FlowSummaryImpl::Private::Steps::summaryLocalStep(_, n, _, _)
24+
}
1725
}
1826

1927
module Consistency = MakeConsistency<Location, CppDataFlow, CppTaintTracking, Input>;

0 commit comments

Comments
 (0)