Skip to content

Commit 4024e83

Browse files
Merge branch 'github:main' into main-1
2 parents 997ab2c + e73745d commit 4024e83

File tree

25 files changed

+217
-31
lines changed

25 files changed

+217
-31
lines changed

.vscode/tasks.json

+10
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
"${input:name}",
5151
"${input:categoryQuery}"
5252
],
53+
"options": {
54+
"env": {
55+
"EDITOR": "code -r",
56+
}
57+
},
5358
"presentation": {
5459
"reveal": "never",
5560
"close": true
@@ -67,6 +72,11 @@
6772
"${input:name}",
6873
"${input:categoryLibrary}"
6974
],
75+
"options": {
76+
"env": {
77+
"EDITOR": "code -r"
78+
}
79+
},
7080
"presentation": {
7181
"reveal": "never",
7282
"close": true

actions/ql/src/change-notes/2025-02-27-immutable-actions-list.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
category: fix
33
---
44
* The `actions/unversioned-immutable-action` query will no longer report any alerts, since the
5-
Immutable Actions feature is not yet available for customer use. The query remains in the
6-
default Code Scanning suites for use internal to GitHub. Once the Immutable Actions feature is
7-
available, the query will be updated to report alerts again.
5+
Immutable Actions feature is not yet available for customer use. The query has also been moved
6+
to the experimental folder and will not be used in code scanning unless it is explicitly added
7+
to a code scanning configuration. Once the Immutable Actions feature is available, the query will
8+
be updated to report alerts again.

actions/ql/src/Security/CWE-829/UnversionedImmutableAction.ql renamed to actions/ql/src/experimental/Security/CWE-829/UnversionedImmutableAction.ql

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* @tags security
99
* actions
1010
* internal
11+
* experimental
1112
* external/cwe/cwe-829
1213
*/
1314

Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Security/CWE-829/UnversionedImmutableAction.ql
1+
experimental/Security/CWE-829/UnversionedImmutableAction.ql

cpp/ql/src/Metrics/Internal/IncludeResolutionStatus.ql

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @name Include file resolution status
3-
* @description A count of successful includes and includes that failed to resolve.
4-
* This query is for internal use only and may change without notice.
3+
* @description Counts unresolved and resolved #includes.
4+
* This query is for internal use only and may change without notice.
55
* @kind table
66
* @id cpp/include-resolution-status
77
*/

csharp/extractor/Semmle.Extraction.CSharp/Entities/Assembly.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public override void Populate(TextWriter trapFile)
3131
{
3232
if (assemblyPath is not null)
3333
{
34-
var isBuildlessOutputAssembly = isOutputAssembly && Context.ExtractionContext.Mode.HasFlag(ExtractorMode.Standalone);
34+
var isBuildlessOutputAssembly = isOutputAssembly && Context.ExtractionContext.IsStandalone;
3535
var identifier = isBuildlessOutputAssembly
3636
? ""
3737
: assembly.ToString() ?? "";
@@ -72,7 +72,7 @@ public static Assembly CreateOutputAssembly(Context cx)
7272

7373
public override void WriteId(EscapingTextWriter trapFile)
7474
{
75-
if (isOutputAssembly && Context.ExtractionContext.Mode.HasFlag(ExtractorMode.Standalone))
75+
if (isOutputAssembly && Context.ExtractionContext.IsStandalone)
7676
{
7777
trapFile.Write("buildlessOutputAssembly");
7878
}

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Invocation.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public IMethodSymbol? TargetSymbol
133133
.Where(method => method.Parameters.Length >= Syntax.ArgumentList.Arguments.Count)
134134
.Where(method => method.Parameters.Count(p => !p.HasExplicitDefaultValue) <= Syntax.ArgumentList.Arguments.Count);
135135

136-
return Context.ExtractionContext.Mode.HasFlag(ExtractorMode.Standalone) ?
136+
return Context.ExtractionContext.IsStandalone ?
137137
candidates.FirstOrDefault() :
138138
candidates.SingleOrDefault();
139139
}

csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/NamedType.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ private class UnderlyingTupleTypeFactory : CachedEntityFactory<INamedTypeSymbol,
166166
// Create typerefs for constructed error types in case they are fully defined elsewhere.
167167
// We cannot use `!this.NeedsPopulation` because this would not be stable as it would depend on
168168
// the assembly that was being extracted at the time.
169-
private bool UsesTypeRef => Symbol.TypeKind == TypeKind.Error || SymbolEqualityComparer.Default.Equals(Symbol.OriginalDefinition, Symbol);
169+
private bool UsesTypeRef =>
170+
Symbol.TypeKind == TypeKind.Error ||
171+
SymbolEqualityComparer.Default.Equals(Symbol.OriginalDefinition, Symbol);
170172

171173
public override Type TypeRef => UsesTypeRef ? (Type)NamedTypeRef.Create(Context, Symbol) : this;
172174
}

csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/Type.cs

+37
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,40 @@ public static bool ConstructedOrParentIsConstructed(INamedTypeSymbol symbol)
2525
symbol.ContainingType is not null && ConstructedOrParentIsConstructed(symbol.ContainingType);
2626
}
2727

28+
29+
/// <summary>
30+
/// A hashset containing the C# contextual keywords that could be confused with types (and typing).
31+
///
32+
/// For the list of all contextual keywords, see
33+
/// https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/#contextual-keywords
34+
/// </summary>
35+
private readonly HashSet<string> ContextualKeywordTypes = [
36+
"dynamic",
37+
"nint",
38+
"nuint",
39+
"var"
40+
];
41+
42+
/// <summary>
43+
/// Returns true in case we suspect this is a broken type.
44+
/// </summary>
45+
/// <param name="symbol">Type symbol</param>
46+
private bool IsBrokenType(ITypeSymbol symbol)
47+
{
48+
if (!Context.ExtractionContext.IsStandalone ||
49+
!symbol.FromSource() ||
50+
symbol.IsAnonymousType)
51+
{
52+
return false;
53+
}
54+
55+
// (1) public class { ... } is a broken type as it doesn't have a name.
56+
// (2) public class var { ... } is an allowed type, but it overrides the `var` keyword for all uses.
57+
// The same goes for other contextual keywords that could be used as type names.
58+
// It is probably a better heuristic to treat these as broken types.
59+
return string.IsNullOrEmpty(symbol.Name) || ContextualKeywordTypes.Contains(symbol.Name);
60+
}
61+
2862
public Kinds.TypeKind GetTypeKind(Context cx, bool constructUnderlyingTupleType)
2963
{
3064
switch (Symbol.SpecialType)
@@ -48,6 +82,9 @@ public Kinds.TypeKind GetTypeKind(Context cx, bool constructUnderlyingTupleType)
4882
if (Symbol.IsBoundNullable())
4983
return Kinds.TypeKind.NULLABLE;
5084

85+
if (IsBrokenType(Symbol))
86+
return Kinds.TypeKind.UNKNOWN;
87+
5188
switch (Symbol.TypeKind)
5289
{
5390
case TypeKind.Class: return Kinds.TypeKind.CLASS;

csharp/extractor/Semmle.Extraction.CSharp/Extractor/BinaryLogExtractionContext.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public BinaryLogExtractionContext(string cwd, string[] args, string outputPath,
4747

4848
public static string? GetAdjustedPath(ExtractionContext extractionContext, string sourcePath)
4949
{
50-
if (extractionContext.Mode.HasFlag(ExtractorMode.BinaryLog)
50+
if (extractionContext.IsBinaryLog
5151
&& extractionContext is BinaryLogExtractionContext binaryLogExtractionContext
5252
&& binaryLogExtractionContext.GetAdjustedPath(sourcePath) is string adjustedPath)
5353
{

csharp/extractor/Semmle.Extraction.CSharp/Extractor/Context.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ private void Populate(ISymbol? optionalSymbol, Entities.CachedEntity entity)
267267

268268
bool duplicationGuard, deferred;
269269

270-
if (ExtractionContext.Mode is ExtractorMode.Standalone)
270+
if (ExtractionContext.IsStandalone)
271271
{
272272
duplicationGuard = false;
273273
deferred = false;
@@ -376,7 +376,7 @@ private void ExtractionError(InternalError error)
376376

377377
private void ReportError(InternalError error)
378378
{
379-
if (!ExtractionContext.Mode.HasFlag(ExtractorMode.Standalone))
379+
if (!ExtractionContext.IsStandalone)
380380
throw error;
381381

382382
ExtractionError(error);

csharp/extractor/Semmle.Extraction.CSharp/Extractor/ExtractionContext.cs

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public class ExtractionContext
1515
public ExtractorMode Mode { get; }
1616
public string OutputPath { get; }
1717
public IEnumerable<CompilationInfo> CompilationInfos { get; }
18+
public bool IsStandalone => Mode.HasFlag(ExtractorMode.Standalone);
19+
public bool IsBinaryLog => Mode.HasFlag(ExtractorMode.BinaryLog);
1820

1921
/// <summary>
2022
/// Creates a new extractor instance for one compilation unit.

csharp/ql/lib/semmle/code/csharp/Type.qll

+2
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,8 @@ class ArglistType extends Type, @arglist_type {
12141214
class UnknownType extends Type, @unknown_type {
12151215
/** Holds if this is the canonical unknown type, and not a type that failed to extract properly. */
12161216
predicate isCanonical() { types(this, _, "<unknown type>") }
1217+
1218+
override string getAPrimaryQlClass() { result = "UnknownType" }
12171219
}
12181220

12191221
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Broken type without a name.
2+
public class { }
3+
4+
// Legal declaration, but we want don't want to use it.
5+
public class var { }
6+
7+
public class C
8+
{
9+
public string Prop { get; set; }
10+
}
11+
12+
13+
public class Program
14+
{
15+
public static void Main()
16+
{
17+
C x1 = new C();
18+
string y1 = x1.Prop;
19+
20+
var x2 = new C(); // Has type `var` as this overrides the implicitly typed keyword `var`.
21+
var y2 = x2.Prop; // Unknown type as `x2` has type `var`.
22+
23+
C2 x3 = new C2(); // Unknown type.
24+
var y3 = x3.Prop; // Unknown property of unknown type.
25+
26+
string s = x1.Prop + x3.Prop;
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
| BrokenTypes.cs:2:14:2:13 | call to constructor Object | object | ObjectType |
2+
| BrokenTypes.cs:5:14:5:16 | call to constructor Object | object | ObjectType |
3+
| BrokenTypes.cs:7:14:7:14 | call to constructor Object | object | ObjectType |
4+
| BrokenTypes.cs:13:14:13:20 | call to constructor Object | object | ObjectType |
5+
| BrokenTypes.cs:17:11:17:12 | access to local variable x1 | C | Class |
6+
| BrokenTypes.cs:17:11:17:22 | C x1 = ... | C | Class |
7+
| BrokenTypes.cs:17:16:17:22 | object creation of type C | C | Class |
8+
| BrokenTypes.cs:18:16:18:17 | access to local variable y1 | string | StringType |
9+
| BrokenTypes.cs:18:16:18:27 | String y1 = ... | string | StringType |
10+
| BrokenTypes.cs:18:21:18:22 | access to local variable x1 | C | Class |
11+
| BrokenTypes.cs:18:21:18:27 | access to property Prop | string | StringType |
12+
| BrokenTypes.cs:20:13:20:14 | access to local variable x2 | var | UnknownType |
13+
| BrokenTypes.cs:20:13:20:24 | var x2 = ... | var | UnknownType |
14+
| BrokenTypes.cs:20:18:20:24 | (...) ... | var | UnknownType |
15+
| BrokenTypes.cs:20:18:20:24 | object creation of type C | C | Class |
16+
| BrokenTypes.cs:21:13:21:14 | access to local variable y2 | var | UnknownType |
17+
| BrokenTypes.cs:21:13:21:24 | var y2 = ... | var | UnknownType |
18+
| BrokenTypes.cs:21:18:21:19 | access to local variable x2 | var | UnknownType |
19+
| BrokenTypes.cs:21:18:21:24 | (...) ... | var | UnknownType |
20+
| BrokenTypes.cs:21:18:21:24 | access to property (unknown) | | UnknownType |
21+
| BrokenTypes.cs:23:12:23:13 | access to local variable x3 | <unknown type> | UnknownType |
22+
| BrokenTypes.cs:23:12:23:24 | <unknown type> x3 = ... | <unknown type> | UnknownType |
23+
| BrokenTypes.cs:23:17:23:24 | object creation of type <unknown type> | <unknown type> | UnknownType |
24+
| BrokenTypes.cs:24:13:24:14 | access to local variable y3 | var | UnknownType |
25+
| BrokenTypes.cs:24:13:24:24 | var y3 = ... | var | UnknownType |
26+
| BrokenTypes.cs:24:18:24:19 | access to local variable x3 | <unknown type> | UnknownType |
27+
| BrokenTypes.cs:24:18:24:24 | (...) ... | var | UnknownType |
28+
| BrokenTypes.cs:24:18:24:24 | access to property (unknown) | | UnknownType |
29+
| BrokenTypes.cs:26:16:26:16 | access to local variable s | string | StringType |
30+
| BrokenTypes.cs:26:16:26:36 | String s = ... | string | StringType |
31+
| BrokenTypes.cs:26:20:26:21 | access to local variable x1 | C | Class |
32+
| BrokenTypes.cs:26:20:26:26 | access to property Prop | string | StringType |
33+
| BrokenTypes.cs:26:20:26:36 | (...) ... | string | StringType |
34+
| BrokenTypes.cs:26:20:26:36 | ... + ... | | UnknownType |
35+
| BrokenTypes.cs:26:30:26:31 | access to local variable x3 | <unknown type> | UnknownType |
36+
| BrokenTypes.cs:26:30:26:36 | access to property (unknown) | | UnknownType |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import csharp
2+
3+
from Expr e, Type t
4+
where e.fromSource() and t = e.getType()
5+
select e, t.toStringWithTypes(), t.getAPrimaryQlClass()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle-extractor-options: --standalone
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import java
2+
import semmle.code.java.dataflow.internal.SsaImpl
3+
import Impl::Consistency

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

+8-5
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,15 @@ private module SsaInput implements SsaImplCommon::InputSig<Location> {
168168
* Holds if the `i`th of basic block `bb` reads source variable `v`.
169169
*/
170170
predicate variableRead(BasicBlock bb, int i, SourceVariable v, boolean certain) {
171-
exists(VarRead use |
172-
v.getAnAccess() = use and bb.getNode(i) = use.getControlFlowNode() and certain = true
171+
hasDominanceInformation(bb) and
172+
(
173+
exists(VarRead use |
174+
v.getAnAccess() = use and bb.getNode(i) = use.getControlFlowNode() and certain = true
175+
)
176+
or
177+
variableCapture(v, _, bb, i) and
178+
certain = false
173179
)
174-
or
175-
variableCapture(v, _, bb, i) and
176-
certain = false
177180
}
178181
}
179182

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

+8-5
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,15 @@ private module SsaInput implements SsaImplCommon::InputSig<Location> {
204204
* This includes implicit reads via calls.
205205
*/
206206
predicate variableRead(BasicBlock bb, int i, SourceVariable v, boolean certain) {
207-
exists(VarRead use |
208-
v.getAnAccess() = use and bb.getNode(i) = use.getControlFlowNode() and certain = true
207+
hasDominanceInformation(bb) and
208+
(
209+
exists(VarRead use |
210+
v.getAnAccess() = use and bb.getNode(i) = use.getControlFlowNode() and certain = true
211+
)
212+
or
213+
variableCapture(v, _, bb, i) and
214+
certain = false
209215
)
210-
or
211-
variableCapture(v, _, bb, i) and
212-
certain = false
213216
}
214217
}
215218

misc/scripts/create-change-note.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22

3-
# Creates a change note and opens it in VSCode for editing.
3+
# Creates a change note and opens it in $EDITOR (or VSCode if the environment
4+
# variable is not set) for editing.
45

56
# Expects to receive the following arguments:
67
# - What language the change note is for
@@ -51,5 +52,6 @@
5152
with open(change_note_file, "w") as f:
5253
f.write(change_note)
5354

54-
# Open the change note file in VSCode, reusing the existing window if possible
55-
os.system(f"code -r {change_note_file}")
55+
editor = os.environ.get('EDITOR', 'code -r')
56+
57+
os.system(f"{editor} {change_note_file}")

ruby/ql/test/library-tests/dataflow/barrier-guards/barrier-guards.expected

-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ newStyleBarrierGuards
1212
| barrier-guards.rb:28:5:28:7 | foo |
1313
| barrier-guards.rb:37:21:38:19 | [input] SSA phi read(foo) |
1414
| barrier-guards.rb:38:5:38:7 | foo |
15-
| barrier-guards.rb:43:16:46:5 | [input] SSA phi read(foo) |
1615
| barrier-guards.rb:45:9:45:11 | foo |
1716
| barrier-guards.rb:70:22:71:19 | [input] SSA phi read(foo) |
1817
| barrier-guards.rb:71:5:71:7 | foo |
@@ -51,9 +50,7 @@ newStyleBarrierGuards
5150
| barrier-guards.rb:199:4:199:15 | [input] SSA phi read(foo) |
5251
| barrier-guards.rb:199:4:199:31 | [input] SSA phi read(foo) |
5352
| barrier-guards.rb:199:20:199:31 | [input] SSA phi read(foo) |
54-
| barrier-guards.rb:203:4:203:15 | [input] SSA phi read(foo) |
5553
| barrier-guards.rb:203:36:203:47 | [input] SSA phi read(foo) |
56-
| barrier-guards.rb:207:21:207:21 | [input] SSA phi read(foo) |
5754
| barrier-guards.rb:207:22:208:19 | [input] SSA phi read(foo) |
5855
| barrier-guards.rb:208:5:208:7 | foo |
5956
| barrier-guards.rb:211:22:212:19 | [input] SSA phi read(foo) |
@@ -64,8 +61,6 @@ newStyleBarrierGuards
6461
| barrier-guards.rb:219:21:219:32 | [input] SSA phi read(foo) |
6562
| barrier-guards.rb:219:95:220:19 | [input] SSA phi read(foo) |
6663
| barrier-guards.rb:220:5:220:7 | foo |
67-
| barrier-guards.rb:227:21:227:21 | [input] SSA phi read(foo) |
68-
| barrier-guards.rb:227:22:228:7 | [input] SSA phi read(foo) |
6964
| barrier-guards.rb:232:18:233:19 | [input] SSA phi read(foo) |
7065
| barrier-guards.rb:233:5:233:7 | foo |
7166
| barrier-guards.rb:237:19:237:38 | [input] SSA phi read(foo) |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
uselessPhiNode
2+
| sqlx.rs:155:5:157:5 | phi | 1 |
3+
phiWithoutTwoPriorRefs
4+
| sqlx.rs:155:5:157:5 | phi | 1 |

0 commit comments

Comments
 (0)