Skip to content

Commit f3bf347

Browse files
author
Paolo Tranquilli
committed
Merge branch 'main' into redsun82/codegen-annotate
2 parents c66bd72 + 575eb24 commit f3bf347

File tree

104 files changed

+1840
-421
lines changed

Some content is hidden

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

104 files changed

+1840
-421
lines changed

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ bazel_dep(name = "bazel_skylib", version = "1.6.1")
2323
bazel_dep(name = "abseil-cpp", version = "20240116.0", repo_name = "absl")
2424
bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "json")
2525
bazel_dep(name = "fmt", version = "10.0.0")
26-
bazel_dep(name = "rules_kotlin", version = "1.9.4-codeql.1")
26+
bazel_dep(name = "rules_kotlin", version = "2.0.0-codeql.1")
2727
bazel_dep(name = "gazelle", version = "0.38.0")
2828
bazel_dep(name = "rules_dotnet", version = "0.15.1")
2929
bazel_dep(name = "googletest", version = "1.14.0.bcr.1")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Added taint flow model for `fopen` and related functions.

cpp/ql/lib/semmle/code/cpp/models/implementations/Fopen.qll

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import semmle.code.cpp.models.interfaces.Alias
77
import semmle.code.cpp.models.interfaces.SideEffect
88

99
/** The function `fopen` and friends. */
10-
private class Fopen extends Function, AliasFunction, SideEffectFunction {
10+
private class Fopen extends Function, AliasFunction, SideEffectFunction, TaintFunction {
1111
Fopen() {
1212
this.hasGlobalOrStdName(["fopen", "fopen_s", "freopen"])
1313
or
@@ -47,4 +47,22 @@ private class Fopen extends Function, AliasFunction, SideEffectFunction {
4747
i = 0 and
4848
buffer = true
4949
}
50+
51+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
52+
(
53+
this.hasGlobalOrStdName(["fopen", "freopen"]) or
54+
this.hasGlobalName(["_wfopen", "_fsopen", "_wfsopen"])
55+
) and
56+
input.isParameterDeref(0) and
57+
output.isReturnValueDeref()
58+
or
59+
// The out parameter is a pointer to a `FILE*`.
60+
this.hasGlobalOrStdName("fopen_s") and
61+
input.isParameterDeref(1) and
62+
output.isParameterDeref(0, 2)
63+
or
64+
this.hasGlobalName(["_open", "_wopen"]) and
65+
input.isParameterDeref(0) and
66+
output.isReturnValue()
67+
}
5068
}

cpp/ql/test/library-tests/dataflow/taint-tests/localTaint.expected

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6584,6 +6584,16 @@ WARNING: module 'TaintTracking' has been deprecated and may be removed in future
65846584
| taint.cpp:767:21:767:24 | ref arg path | taint.cpp:768:8:768:11 | path | |
65856585
| taint.cpp:768:8:768:11 | path | taint.cpp:768:7:768:11 | * ... | |
65866586
| taint.cpp:778:37:778:42 | call to source | taint.cpp:779:7:779:9 | obj | |
6587+
| taint.cpp:785:23:785:28 | source | taint.cpp:785:23:785:28 | source | |
6588+
| taint.cpp:785:23:785:28 | source | taint.cpp:786:18:786:23 | source | |
6589+
| taint.cpp:785:23:785:28 | source | taint.cpp:790:15:790:20 | source | |
6590+
| taint.cpp:786:12:786:16 | call to fopen | taint.cpp:787:7:787:7 | f | |
6591+
| taint.cpp:786:18:786:23 | source | taint.cpp:786:12:786:16 | call to fopen | TAINT |
6592+
| taint.cpp:789:8:789:9 | f2 | taint.cpp:790:11:790:12 | f2 | |
6593+
| taint.cpp:789:8:789:9 | f2 | taint.cpp:791:7:791:8 | f2 | |
6594+
| taint.cpp:790:10:790:12 | ref arg & ... | taint.cpp:790:11:790:12 | f2 [inner post update] | |
6595+
| taint.cpp:790:10:790:12 | ref arg & ... | taint.cpp:791:7:791:8 | f2 | |
6596+
| taint.cpp:790:11:790:12 | f2 | taint.cpp:790:10:790:12 | & ... | |
65876597
| vector.cpp:16:43:16:49 | source1 | vector.cpp:17:26:17:32 | source1 | |
65886598
| vector.cpp:16:43:16:49 | source1 | vector.cpp:31:38:31:44 | source1 | |
65896599
| vector.cpp:17:21:17:33 | call to vector | vector.cpp:19:14:19:14 | v | |

cpp/ql/test/library-tests/dataflow/taint-tests/taint.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,4 +777,16 @@ TaintInheritingContentObject source(bool);
777777
void test_TaintInheritingContent() {
778778
TaintInheritingContentObject obj = source(true);
779779
sink(obj.flowFromObject); // $ ir MISSING: ast
780+
}
781+
782+
FILE* fopen(const char*, const char*);
783+
int fopen_s(FILE** pFile, const char *filename, const char *mode);
784+
785+
void fopen_test(char* source) {
786+
FILE* f = fopen(source, "r");
787+
sink(f); // $ ast,ir
788+
789+
FILE* f2;
790+
fopen_s(&f2, source, "r");
791+
sink(f2); // $ ast,ir
780792
}

csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ private predicate idOf(AstNode x, int y) = equivalenceRelation(id/2)(x, y)
5353
private module CfgInput implements CfgShared::InputSig<Location> {
5454
private import ControlFlowGraphImpl as Impl
5555
private import Completion as Comp
56-
private import Splitting as Splitting
5756
private import SuccessorType as ST
5857
private import semmle.code.csharp.Caching
5958

@@ -80,10 +79,6 @@ private module CfgInput implements CfgShared::InputSig<Location> {
8079
Impl::scopeLast(scope, last, c)
8180
}
8281

83-
class SplitKindBase = Splitting::TSplitKind;
84-
85-
class Split = Splitting::Split;
86-
8782
class SuccessorType = ST::SuccessorType;
8883

8984
SuccessorType getAMatchingSuccessorType(Completion c) { result = c.getAMatchingSuccessorType() }
@@ -102,7 +97,21 @@ private module CfgInput implements CfgShared::InputSig<Location> {
10297
}
10398
}
10499

105-
import CfgShared::Make<Location, CfgInput>
100+
private module CfgSplittingInput implements CfgShared::SplittingInputSig<Location, CfgInput> {
101+
private import Splitting as S
102+
103+
class SplitKindBase = S::TSplitKind;
104+
105+
class Split = S::Split;
106+
}
107+
108+
private module ConditionalCompletionSplittingInput implements
109+
CfgShared::ConditionalCompletionSplittingInputSig<Location, CfgInput, CfgSplittingInput>
110+
{
111+
import Splitting::ConditionalCompletionSplitting::ConditionalCompletionSplittingInput
112+
}
113+
114+
import CfgShared::MakeWithSplitting<Location, CfgInput, CfgSplittingInput, ConditionalCompletionSplittingInput>
106115

107116
/**
108117
* A compilation.

csharp/ql/lib/semmle/code/csharp/controlflow/internal/Splitting.qll

Lines changed: 46 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
*/
66

77
import csharp
8-
private import Completion
8+
private import Completion as Comp
9+
private import Comp
910
private import ControlFlowGraphImpl
1011
private import semmle.code.csharp.controlflow.ControlFlowGraph::ControlFlow as Cfg
1112
private import semmle.code.csharp.controlflow.internal.PreSsa
@@ -260,100 +261,77 @@ module ConditionalCompletionSplitting {
260261

261262
ConditionalCompletionSplit() { this = TConditionalCompletionSplit(completion) }
262263

264+
ConditionalCompletion getCompletion() { result = completion }
265+
263266
override string toString() { result = completion.toString() }
264267
}
265268

266-
private class ConditionalCompletionSplitKind extends SplitKind, TConditionalCompletionSplitKind {
269+
private class ConditionalCompletionSplitKind_ extends SplitKind, TConditionalCompletionSplitKind {
267270
override int getListOrder() { result = InitializerSplitting::getNextListOrder() }
268271

269272
override predicate isEnabled(AstNode cfe) { this.appliesTo(cfe) }
270273

271274
override string toString() { result = "ConditionalCompletion" }
272275
}
273276

274-
int getNextListOrder() { result = InitializerSplitting::getNextListOrder() + 1 }
277+
module ConditionalCompletionSplittingInput {
278+
private import Completion as Comp
275279

276-
private class ConditionalCompletionSplitImpl extends SplitImpl instanceof ConditionalCompletionSplit
277-
{
278-
ConditionalCompletion completion;
280+
class ConditionalCompletion = Comp::ConditionalCompletion;
279281

280-
ConditionalCompletionSplitImpl() { this = TConditionalCompletionSplit(completion) }
282+
class ConditionalCompletionSplitKind extends ConditionalCompletionSplitKind_, TSplitKind { }
281283

282-
override ConditionalCompletionSplitKind getKind() { any() }
284+
class ConditionalCompletionSplit = ConditionalCompletionSplitting::ConditionalCompletionSplit;
283285

284-
override predicate hasEntry(AstNode pred, AstNode succ, Completion c) {
285-
succ(pred, succ, c) and
286-
last(succ, _, completion) and
286+
bindingset[parent, parentCompletion]
287+
predicate condPropagateExpr(
288+
AstNode parent, ConditionalCompletion parentCompletion, AstNode child,
289+
ConditionalCompletion childCompletion
290+
) {
291+
child = parent.(LogicalNotExpr).getOperand() and
292+
childCompletion.getDual() = parentCompletion
293+
or
294+
childCompletion = parentCompletion and
287295
(
288-
last(succ.(LogicalNotExpr).getOperand(), pred, c) and
289-
completion.(BooleanCompletion).getDual() = c
296+
child = parent.(LogicalAndExpr).getAnOperand()
290297
or
291-
last(succ.(LogicalAndExpr).getAnOperand(), pred, c) and
292-
completion = c
298+
child = parent.(LogicalOrExpr).getAnOperand()
293299
or
294-
last(succ.(LogicalOrExpr).getAnOperand(), pred, c) and
295-
completion = c
300+
parent = any(ConditionalExpr ce | child = [ce.getThen(), ce.getElse()])
296301
or
297-
succ =
298-
any(ConditionalExpr ce |
299-
last([ce.getThen(), ce.getElse()], pred, c) and
300-
completion = c
301-
)
302+
child = parent.(SwitchExpr).getACase()
302303
or
303-
succ =
304+
child = parent.(SwitchCaseExpr).getBody()
305+
or
306+
parent =
304307
any(NullCoalescingExpr nce |
305-
exists(Expr operand |
306-
last(operand, pred, c) and
307-
completion = c
308-
|
309-
if c instanceof NullnessCompletion
310-
then operand = nce.getRightOperand()
311-
else operand = nce.getAnOperand()
312-
)
308+
if childCompletion instanceof NullnessCompletion
309+
then child = nce.getRightOperand()
310+
else child = nce.getAnOperand()
313311
)
312+
)
313+
or
314+
child = parent.(NotPatternExpr).getPattern() and
315+
childCompletion.getDual() = parentCompletion
316+
or
317+
child = parent.(IsExpr).getPattern() and
318+
parentCompletion.(BooleanCompletion).getValue() =
319+
childCompletion.(MatchingCompletion).getValue()
320+
or
321+
childCompletion = parentCompletion and
322+
(
323+
child = parent.(AndPatternExpr).getAnOperand()
314324
or
315-
last(succ.(SwitchExpr).getACase(), pred, c) and
316-
completion = c
317-
or
318-
last(succ.(SwitchCaseExpr).getBody(), pred, c) and
319-
completion = c
320-
or
321-
last(succ.(NotPatternExpr).getPattern(), pred, c) and
322-
completion.(MatchingCompletion).getDual() = c
323-
or
324-
last(succ.(IsExpr).getPattern(), pred, c) and
325-
completion.(BooleanCompletion).getValue() = c.(MatchingCompletion).getValue()
326-
or
327-
last(succ.(AndPatternExpr).getAnOperand(), pred, c) and
328-
completion = c
329-
or
330-
last(succ.(OrPatternExpr).getAnOperand(), pred, c) and
331-
completion = c
325+
child = parent.(OrPatternExpr).getAnOperand()
332326
or
333-
last(succ.(RecursivePatternExpr).getAChildExpr(), pred, c) and
334-
completion = c
327+
child = parent.(RecursivePatternExpr).getAChildExpr()
335328
or
336-
last(succ.(PropertyPatternExpr).getPattern(_), pred, c) and
337-
completion = c
329+
child = parent.(PropertyPatternExpr).getPattern(_)
338330
)
339331
}
340-
341-
override predicate hasEntryScope(CfgScope scope, AstNode first) { none() }
342-
343-
override predicate hasExit(AstNode pred, AstNode succ, Completion c) {
344-
this.appliesTo(pred) and
345-
succ(pred, succ, c) and
346-
if c instanceof ConditionalCompletion then completion = c else any()
347-
}
348-
349-
override predicate hasExitScope(CfgScope scope, AstNode last, Completion c) {
350-
this.appliesTo(last) and
351-
scopeLast(scope, last, c) and
352-
if c instanceof ConditionalCompletion then completion = c else any()
353-
}
354-
355-
override predicate hasSuccessor(AstNode pred, AstNode succ, Completion c) { none() }
356332
}
333+
334+
int getNextListOrder() { result = InitializerSplitting::getNextListOrder() + 1 }
357335
}
358336

359337
module AssertionSplitting {

docs/codeql/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ <h2 class="Box-title text-mono f2 text-center">
101101
latest version of CodeQL...</div>
102102
</div>
103103
<div class="Subhead border-0">
104-
<a href="codeql-overview/supported-languages-and-frameworks/">
104+
<a href="query-help/codeql-cwe-coverage/">
105105
<div class="Subhead-heading f4 text-center">CodeQL coverage of CWEs</div>
106106
</a>
107107
<div class="Subhead-description">Detailed information on the coverage of Common Weakness Enumerations (CWEs) in the latest release...</div>

misc/bazel/registry/modules/rules_kotlin/1.9.4-codeql.1/source.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

misc/bazel/registry/modules/rules_kotlin/1.9.4-codeql.1/MODULE.bazel renamed to misc/bazel/registry/modules/rules_kotlin/2.0.0-codeql.1/MODULE.bazel

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
module(
22
name = "rules_kotlin",
3-
version = "1.9.4-codeql.1",
3+
version = "2.0.0-codeql.1",
4+
compatibility_level = 1,
45
repo_name = "rules_kotlin",
56
)
67

7-
bazel_dep(name = "platforms", version = "0.0.6")
8-
bazel_dep(name = "bazel_skylib", version = "1.4.2")
8+
bazel_dep(name = "platforms", version = "0.0.10")
9+
bazel_dep(name = "bazel_skylib", version = "1.7.1")
910
bazel_dep(name = "rules_java", version = "7.2.0")
1011
bazel_dep(name = "rules_python", version = "0.23.1")
1112
bazel_dep(name = "rules_cc", version = "0.0.8")
13+
bazel_dep(name = "rules_android", version = "0.1.1")
1214

1315
rules_kotlin_extensions = use_extension(
1416
"//src/main/starlark/core/repositories:bzlmod_setup.bzl",
@@ -19,7 +21,9 @@ use_repo(
1921
"com_github_google_ksp",
2022
"com_github_jetbrains_kotlin",
2123
"com_github_pinterest_ktlint",
22-
"rules_android",
24+
"kotlinx_serialization_core_jvm",
25+
"kotlinx_serialization_json",
26+
"kotlinx_serialization_json_jvm",
2327
)
2428

2529
register_toolchains("//kotlin/internal:default_toolchain")

0 commit comments

Comments
 (0)