Skip to content

Commit 2f505c5

Browse files
authored
Merge branch 'main' into experimental-decompression-api
2 parents 78f5186 + fc7e0ec commit 2f505c5

File tree

81 files changed

+3153
-168
lines changed

Some content is hidden

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

81 files changed

+3153
-168
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ go/main
5858
# node_modules folders except in the JS test suite
5959
node_modules/
6060
!/javascript/ql/test/**/node_modules/
61+
62+
# Temporary folders for working with generated models
63+
.model-temp

cpp/ql/test/TestUtilities/InlineExpectationsTest.qll

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,24 @@ private string getColumnString(TColumn column) {
239239

240240
/**
241241
* RegEx pattern to match a single expected result, not including the leading `$`. It consists of one or
242-
* more comma-separated tags containing only letters, digits, `-` and `_` (note that the first character
243-
* must not be a digit), optionally followed by `=` and the expected value.
242+
* more comma-separated tags optionally followed by `=` and the expected value.
243+
*
244+
* Tags must be only letters, digits, `-` and `_` (note that the first character
245+
* must not be a digit), but can contain anything enclosed in a single set of
246+
* square brackets.
247+
*
248+
* Examples:
249+
* - `tag`
250+
* - `tag=value`
251+
* - `tag,tag2=value`
252+
* - `tag[foo bar]=value`
253+
*
254+
* Not allowed:
255+
* - `tag[[[foo bar]`
244256
*/
245257
private string expectationPattern() {
246258
exists(string tag, string tags, string value |
247-
tag = "[A-Za-z-_][A-Za-z-_0-9]*" and
259+
tag = "[A-Za-z-_](?:[A-Za-z-_0-9]|\\[[^\\]\\]]*\\])*" and
248260
tags = "((?:" + tag + ")(?:\\s*,\\s*" + tag + ")*)" and
249261
// In Python, we allow both `"` and `'` for strings, as well as the prefixes `bru`.
250262
// For example, `b"foo"`.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using Microsoft.CodeAnalysis;
2+
using Microsoft.CodeAnalysis.CSharp.Syntax;
3+
using Semmle.Extraction.CSharp.Entities.Statements;
4+
using System.Collections.Generic;
5+
using System.IO;
6+
7+
namespace Semmle.Extraction.CSharp.Entities
8+
{
9+
internal class ImplicitMainMethod : OrdinaryMethod
10+
{
11+
private readonly List<GlobalStatementSyntax> globalStatements;
12+
13+
public ImplicitMainMethod(Context cx, IMethodSymbol symbol, List<GlobalStatementSyntax> globalStatements)
14+
: base(cx, symbol)
15+
{
16+
this.globalStatements = globalStatements;
17+
}
18+
19+
protected override void PopulateMethodBody(TextWriter trapFile)
20+
{
21+
GlobalStatementsBlock.Create(Context, this, globalStatements);
22+
}
23+
24+
public static ImplicitMainMethod Create(Context cx, IMethodSymbol method, List<GlobalStatementSyntax> globalStatements)
25+
{
26+
return ImplicitMainMethodFactory.Instance.CreateEntity(cx, method, (method, globalStatements));
27+
}
28+
29+
private class ImplicitMainMethodFactory : CachedEntityFactory<(IMethodSymbol, List<GlobalStatementSyntax>), ImplicitMainMethod>
30+
{
31+
public static ImplicitMainMethodFactory Instance { get; } = new ImplicitMainMethodFactory();
32+
33+
public override ImplicitMainMethod Create(Context cx, (IMethodSymbol, List<GlobalStatementSyntax>) init) => new ImplicitMainMethod(cx, init.Item1, init.Item2);
34+
}
35+
}
36+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected virtual void ExtractInitializers(TextWriter trapFile)
4646
// so there's nothing to extract.
4747
}
4848

49-
private void PopulateMethodBody(TextWriter trapFile)
49+
protected virtual void PopulateMethodBody(TextWriter trapFile)
5050
{
5151
if (!IsSourceDeclaration)
5252
return;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Semmle.Extraction.CSharp.Entities
88
{
99
internal class OrdinaryMethod : Method
1010
{
11-
private OrdinaryMethod(Context cx, IMethodSymbol init)
11+
protected OrdinaryMethod(Context cx, IMethodSymbol init)
1212
: base(cx, init) { }
1313

1414
public override string Name => Symbol.GetName();

csharp/extractor/Semmle.Extraction.CSharp/Entities/Statements/GlobalStatementsBlock.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@
22
using System.Linq;
33
using System.IO;
44
using Semmle.Extraction.Entities;
5+
using System.Collections.Generic;
6+
using Microsoft.CodeAnalysis.CSharp.Syntax;
7+
using System;
58

69
namespace Semmle.Extraction.CSharp.Entities.Statements
710
{
811
internal class GlobalStatementsBlock : Statement
912
{
1013
private readonly Method parent;
14+
private readonly List<GlobalStatementSyntax> globalStatements;
1115

12-
private GlobalStatementsBlock(Context cx, Method parent)
16+
private GlobalStatementsBlock(Context cx, Method parent, List<GlobalStatementSyntax> globalStatements)
1317
: base(cx, StmtKind.BLOCK, parent, 0)
1418
{
1519
this.parent = parent;
20+
this.globalStatements = globalStatements;
1621
}
1722

1823
public override Microsoft.CodeAnalysis.Location? ReportingLocation
@@ -27,16 +32,24 @@ public override Microsoft.CodeAnalysis.Location? ReportingLocation
2732
}
2833
}
2934

30-
public static GlobalStatementsBlock Create(Context cx, Method parent)
35+
public static GlobalStatementsBlock Create(Context cx, Method parent, List<GlobalStatementSyntax> globalStatements)
3136
{
32-
var ret = new GlobalStatementsBlock(cx, parent);
37+
var ret = new GlobalStatementsBlock(cx, parent, globalStatements);
3338
ret.TryPopulate();
3439
return ret;
3540
}
3641

3742
protected override void PopulateStatement(TextWriter trapFile)
3843
{
3944
trapFile.stmt_location(this, Context.CreateLocation(ReportingLocation));
45+
46+
for (var i = 0; i < globalStatements.Count; i++)
47+
{
48+
if (globalStatements[i].Statement is not null)
49+
{
50+
Statement.Create(Context, globalStatements[i].Statement, this, i);
51+
}
52+
}
4053
}
4154
}
4255
}

csharp/extractor/Semmle.Extraction.CSharp/Populators/CompilationUnitVisitor.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using Microsoft.CodeAnalysis.CSharp.Syntax;
44
using Semmle.Util.Logging;
55
using Semmle.Extraction.CSharp.Entities;
6-
using Semmle.Extraction.CSharp.Entities.Statements;
76
using System.Linq;
87

98
namespace Semmle.Extraction.CSharp.Populators
@@ -60,23 +59,14 @@ private void ExtractGlobalStatements(CompilationUnitSyntax compilationUnit)
6059
}
6160

6261
var entryPoint = Cx.Compilation.GetEntryPoint(System.Threading.CancellationToken.None);
63-
var entryMethod = Method.Create(Cx, entryPoint);
64-
if (entryMethod is null)
62+
if (entryPoint is null)
6563
{
6664
Cx.ExtractionError("No entry method found. Skipping the extraction of global statements.",
6765
null, Cx.CreateLocation(globalStatements[0].GetLocation()), null, Severity.Info);
6866
return;
6967
}
7068

71-
var block = GlobalStatementsBlock.Create(Cx, entryMethod);
72-
73-
for (var i = 0; i < globalStatements.Count; i++)
74-
{
75-
if (globalStatements[i].Statement is not null)
76-
{
77-
Statement.Create(Cx, globalStatements[i].Statement, block, i);
78-
}
79-
}
69+
ImplicitMainMethod.Create(Cx, entryPoint, globalStatements);
8070
}
8171
}
8272
}

csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsources/Remote.qll

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,23 @@ class ActionMethodParameter extends RemoteFlowSource, DataFlow::ParameterNode {
171171
/** A data flow source of remote user input (ASP.NET Core). */
172172
abstract class AspNetCoreRemoteFlowSource extends RemoteFlowSource { }
173173

174+
/**
175+
* Data flow for AST.NET Core.
176+
*
177+
* Flow is defined from any ASP.NET Core remote source object to any of its member
178+
* properties.
179+
*/
180+
private class AspNetCoreRemoteFlowSourceMember extends TaintTracking::TaintedMember {
181+
AspNetCoreRemoteFlowSourceMember() {
182+
this.getDeclaringType() = any(AspNetCoreRemoteFlowSource source).getType() and
183+
this.isPublic() and
184+
not this.isStatic() and
185+
exists(Property p | p = this |
186+
p.isAutoImplemented() and p.getGetter().isPublic() and p.getSetter().isPublic()
187+
)
188+
}
189+
}
190+
174191
/** A data flow source of remote user input (ASP.NET query collection). */
175192
class AspNetCoreQueryRemoteFlowSource extends AspNetCoreRemoteFlowSource, DataFlow::ExprNode {
176193
AspNetCoreQueryRemoteFlowSource() {
@@ -196,7 +213,7 @@ class AspNetCoreQueryRemoteFlowSource extends AspNetCoreRemoteFlowSource, DataFl
196213
}
197214

198215
/** A parameter to a `Mvc` controller action method, viewed as a source of remote user input. */
199-
class AspNetCoreActionMethodParameter extends RemoteFlowSource, DataFlow::ParameterNode {
216+
class AspNetCoreActionMethodParameter extends AspNetCoreRemoteFlowSource, DataFlow::ParameterNode {
200217
AspNetCoreActionMethodParameter() {
201218
exists(Parameter p |
202219
p = this.getParameter() and

csharp/ql/src/Diagnostics/CompilerError.ql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/**
22
* @name Compilation error
33
* @description A compilation error can cause extraction problems, and could lead to inaccurate results.
4-
* @kind problem
5-
* @problem.severity recommendation
6-
* @precision high
4+
* @kind diagnostic
75
* @id cs/compilation-error
86
* @tags internal non-attributable
97
*/

csharp/ql/src/Diagnostics/CompilerMessage.ql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/**
22
* @name Compilation message
33
* @description A message emitted by the compiler, including warnings and errors.
4-
* @kind problem
5-
* @problem.severity recommendation
6-
* @precision high
4+
* @kind diagnostic
75
* @id cs/compilation-message
86
* @tags internal non-attributable
97
*/

0 commit comments

Comments
 (0)