Skip to content

Commit 1ae28c7

Browse files
committed
Merge branch 'main' into rust-cleartext-transmission
2 parents 4de69c7 + 4681f28 commit 1ae28c7

File tree

107 files changed

+2413
-216
lines changed

Some content is hidden

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

107 files changed

+2413
-216
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MODULE.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ use_repo(
7373
tree_sitter_extractors_deps,
7474
"vendor_ts__anyhow-1.0.96",
7575
"vendor_ts__argfile-0.2.1",
76+
"vendor_ts__chalk-ir-0.99.0",
7677
"vendor_ts__chrono-0.4.39",
7778
"vendor_ts__clap-4.5.31",
7879
"vendor_ts__dunce-1.0.5",
@@ -94,6 +95,7 @@ use_repo(
9495
"vendor_ts__ra_ap_hir-0.0.266",
9596
"vendor_ts__ra_ap_hir_def-0.0.266",
9697
"vendor_ts__ra_ap_hir_expand-0.0.266",
98+
"vendor_ts__ra_ap_hir_ty-0.0.266",
9799
"vendor_ts__ra_ap_ide_db-0.0.266",
98100
"vendor_ts__ra_ap_intern-0.0.266",
99101
"vendor_ts__ra_ap_load-cargo-0.0.266",
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
- description: Security-and-quality queries for GitHub Actions
2-
- import: codeql-suites/actions-security-extended.qls
2+
- queries: .
3+
- apply: security-and-quality-selectors.yml
4+
from: codeql/suite-helpers
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
- description: Extended and experimental security queries for GitHub Actions
2-
- import: codeql-suites/actions-code-scanning.qls
2+
- queries: .
3+
- apply: security-experimental-selectors.yml
4+
from: codeql/suite-helpers

csharp/ql/src/Bad Practices/Control-Flow/ConstantCondition.ql

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,14 @@ class ConstantMatchingCondition extends ConstantCondition {
119119
}
120120

121121
override predicate isWhiteListed() {
122-
exists(SwitchExpr se, int i |
123-
se.getCase(i).getPattern() = this.(DiscardExpr) and
122+
exists(Switch se, Case c, int i |
123+
c = se.getCase(i) and
124+
c.getPattern() = this.(DiscardExpr)
125+
|
124126
i > 0
127+
or
128+
i = 0 and
129+
exists(Expr cond | c.getCondition() = cond and not isConstantCondition(cond, true))
125130
)
126131
or
127132
this = any(PositionalPatternExpr ppe).getPattern(_)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Increase query precision for `cs/constant-condition` and allow the use of discards in switch/case statements and also take the condition (if any) into account.

csharp/ql/src/codeql-suites/csharp-ccr.qls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
- cs/inefficient-containskey
1010
- cs/call-to-object-tostring
1111
- cs/local-not-disposed
12+
- cs/constant-condition

csharp/ql/test/query-tests/API Abuse/NoDisposeCallOnLocalIDisposable/Class1.cs_

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

csharp/ql/test/query-tests/API Abuse/NoDisposeCallOnLocalIDisposable/NoDisposeCallOnLocalIDisposable.cs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using System;
2-
using System.Text;
32
using System.IO;
43
using System.IO.Compression;
5-
using System.Xml;
4+
using System.Net.Http;
5+
using System.Text;
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using System.Xml;
89

910
class Test
1011
{
@@ -48,9 +49,9 @@ public IDisposable Method()
4849
}
4950

5051
// BAD: No Dispose call
51-
var c1d = new Timer(TimerProc);
52-
var fs = new FileStream("", FileMode.CreateNew, FileAccess.Write);
53-
new FileStream("", FileMode.CreateNew, FileAccess.Write).Fluent();
52+
var c1d = new Timer(TimerProc); // $ Alert
53+
var fs = new FileStream("", FileMode.CreateNew, FileAccess.Write); // $ Alert
54+
new FileStream("", FileMode.CreateNew, FileAccess.Write).Fluent(); // $ Alert
5455

5556
// GOOD: Disposed via wrapper
5657
fs = new FileStream("", FileMode.CreateNew, FileAccess.Write);
@@ -72,13 +73,10 @@ public IDisposable Method()
7273
;
7374

7475
// GOOD: XmlDocument.Load disposes incoming XmlReader (False positive as this is disposed in library code)
75-
var xmlReader = XmlReader.Create(new StringReader("xml"), null);
76+
var xmlReader = XmlReader.Create(new StringReader("xml"), null); // $ Alert
7677
var xmlDoc = new XmlDocument();
7778
xmlDoc.Load(xmlReader);
7879

79-
// GOOD: Passed to a library (False positive as this is disposed in library code).
80-
DisposalTests.Class1.Dispose(new StreamWriter("output.txt"));
81-
8280
// GOOD: Disposed automatically.
8381
using var c2 = new Timer(TimerProc);
8482

@@ -97,6 +95,15 @@ public IDisposable Method()
9795
return null;
9896
}
9997

98+
public void M(IHttpClientFactory factory)
99+
{
100+
// GOOD: Factory tracks and disposes.
101+
HttpClient client1 = factory.CreateClient();
102+
103+
// BAD: No Dispose call
104+
var client2 = new HttpClient(); // $ Alert
105+
}
106+
100107
// GOOD: Escapes
101108
IDisposable Create() => new Timer(TimerProc);
102109

@@ -107,6 +114,15 @@ void TimerProc(object obj)
107114
public void Dispose() { }
108115
}
109116

117+
class Bad
118+
{
119+
long GetLength(string file)
120+
{
121+
var stream = new FileStream(file, FileMode.Open); // $ Alert
122+
return stream.Length;
123+
}
124+
}
125+
110126
static class Extensions
111127
{
112128
public static FileStream Fluent(this FileStream fs) => fs;

0 commit comments

Comments
 (0)