Skip to content

Commit b4bb24a

Browse files
committed
Merge remote-tracking branch 'upstream/main' into aibaars/rust-macros
2 parents 6ade2a8 + 854d766 commit b4bb24a

File tree

110 files changed

+2006
-561
lines changed

Some content is hidden

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

110 files changed

+2006
-561
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/PrintAST.qll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ private Declaration getAnEnclosingDeclaration(Locatable ast) {
8080
or
8181
result = ast.(Parameter).getFunction()
8282
or
83+
result = ast.(Parameter).getCatchBlock().getEnclosingFunction()
84+
or
8385
result = ast.(Expr).getEnclosingDeclaration()
8486
or
8587
result = ast.(Initializer).getDeclaration()
@@ -510,6 +512,22 @@ class DeclStmtNode extends StmtNode {
510512
}
511513
}
512514

515+
/**
516+
* A node representing a `Handler`.
517+
*/
518+
class HandlerNode extends ChildStmtNode {
519+
Handler handler;
520+
521+
HandlerNode() { handler = stmt }
522+
523+
override BaseAstNode getChildInternal(int childIndex) {
524+
result = super.getChildInternal(childIndex)
525+
or
526+
childIndex = -1 and
527+
result.getAst() = handler.getParameter()
528+
}
529+
}
530+
513531
/**
514532
* A node representing a `Parameter`.
515533
*/
@@ -754,6 +772,8 @@ private predicate namedStmtChildPredicates(Locatable s, Element e, string pred)
754772
or
755773
s.(ConstexprIfStmt).getElse() = e and pred = "getElse()"
756774
or
775+
s.(Handler).getParameter() = e and pred = "getParameter()"
776+
or
757777
s.(IfStmt).getInitialization() = e and pred = "getInitialization()"
758778
or
759779
s.(IfStmt).getCondition() = e and pred = "getCondition()"

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/examples/expressions/PrintAST.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,8 @@ Throw.cpp:
870870
# 8| Type = [BoolType] bool
871871
# 8| ValueCategory = prvalue
872872
# 12| getChild(1): [Handler] <handler>
873+
# 12| getParameter(): [Parameter] e
874+
# 12| Type = [PointerType] E *
873875
# 12| getBlock(): [CatchBlock] { ... }
874876
# 13| getStmt(0): [ExprStmt] ExprStmt
875877
# 13| getExpr(): [ReThrowExpr] re-throw exception

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
}

cpp/ql/test/library-tests/ir/ir/PrintAST.expected

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9055,6 +9055,8 @@ ir.cpp:
90559055
# 733| Value = [Literal] 7
90569056
# 733| ValueCategory = prvalue
90579057
# 735| getChild(1): [Handler] <handler>
9058+
# 735| getParameter(): [Parameter] s
9059+
# 735| Type = [PointerType] const char *
90589060
# 735| getBlock(): [CatchBlock] { ... }
90599061
# 736| getStmt(0): [ExprStmt] ExprStmt
90609062
# 736| getExpr(): [ThrowExpr] throw ...
@@ -9067,6 +9069,8 @@ ir.cpp:
90679069
# 736| Type = [PointerType] const char *
90689070
# 736| ValueCategory = prvalue(load)
90699071
# 738| getChild(2): [Handler] <handler>
9072+
# 738| getParameter(): [Parameter] e
9073+
# 738| Type = [LValueReferenceType] const String &
90709074
# 738| getBlock(): [CatchBlock] { ... }
90719075
# 740| getChild(3): [Handler] <handler>
90729076
# 740| getBlock(): [CatchAnyBlock] { ... }
@@ -12852,6 +12856,8 @@ ir.cpp:
1285212856
# 1200| Value = [Literal] 7
1285312857
# 1200| ValueCategory = prvalue
1285412858
# 1202| getChild(1): [Handler] <handler>
12859+
# 1202| getParameter(): [Parameter] s
12860+
# 1202| Type = [PointerType] const char *
1285512861
# 1202| getBlock(): [CatchBlock] { ... }
1285612862
# 1203| getStmt(0): [ExprStmt] ExprStmt
1285712863
# 1203| getExpr(): [ThrowExpr] throw ...
@@ -12864,6 +12870,8 @@ ir.cpp:
1286412870
# 1203| Type = [PointerType] const char *
1286512871
# 1203| ValueCategory = prvalue(load)
1286612872
# 1205| getChild(2): [Handler] <handler>
12873+
# 1205| getParameter(): [Parameter] e
12874+
# 1205| Type = [LValueReferenceType] const String &
1286712875
# 1205| getBlock(): [CatchBlock] { ... }
1286812876
# 1207| getStmt(1): [ReturnStmt] return ...
1286912877
# 1211| [TopLevelFunction] void VectorTypes(int)
@@ -20586,6 +20594,8 @@ ir.cpp:
2058620594
# 2281| Type = [Struct] String
2058720595
# 2281| ValueCategory = lvalue
2058820596
# 2282| getChild(1): [Handler] <handler>
20597+
# 2282| getParameter(): [Parameter] s
20598+
# 2282| Type = [PointerType] const char *
2058920599
# 2282| getBlock(): [CatchBlock] { ... }
2059020600
# 2283| getStmt(0): [ExprStmt] ExprStmt
2059120601
# 2283| getExpr(): [ThrowExpr] throw ...
@@ -20598,6 +20608,8 @@ ir.cpp:
2059820608
# 2283| Type = [PointerType] const char *
2059920609
# 2283| ValueCategory = prvalue(load)
2060020610
# 2285| getChild(2): [Handler] <handler>
20611+
# 2285| getParameter(): [Parameter] e
20612+
# 2285| Type = [LValueReferenceType] const String &
2060120613
# 2285| getBlock(): [CatchBlock] { ... }
2060220614
# 2287| getChild(3): [Handler] <handler>
2060320615
# 2287| getBlock(): [CatchAnyBlock] { ... }
@@ -22845,6 +22857,8 @@ ir.cpp:
2284522857
# 2537| Value = [Literal] 42
2284622858
# 2537| ValueCategory = prvalue
2284722859
# 2539| getChild(1): [Handler] <handler>
22860+
# 2539| getParameter(): [Parameter] (unnamed parameter 0)
22861+
# 2539| Type = [PlainCharType] char
2284822862
# 2539| getBlock(): [CatchBlock] { ... }
2284922863
# 2541| getImplicitDestructorCall(0): [DestructorCall] call to ~ClassWithDestructor
2285022864
# 2541| Type = [VoidType] void

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.

0 commit comments

Comments
 (0)