Skip to content

Commit b7402fe

Browse files
committed
Merge remote-tracking branch 'upstream/main' into lifetimetest
2 parents 3cdbef7 + 8b89e15 commit b7402fe

File tree

160 files changed

+16779
-1626
lines changed

Some content is hidden

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

160 files changed

+16779
-1626
lines changed

.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.1.1
1+
8.4.2

cpp/ql/src/Security/CWE/CWE-020/ExternalAPIs.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import ExternalAPIsSpecific
1010

1111
/** A node representing untrusted data being passed to an external API. */
1212
class UntrustedExternalApiDataNode extends ExternalApiDataNode {
13-
UntrustedExternalApiDataNode() { UntrustedDataToExternalApiFlow::flow(_, this) }
13+
UntrustedExternalApiDataNode() { UntrustedDataToExternalApiFlow::flowTo(this) }
1414

1515
/** Gets a source of untrusted data which is passed to this external API data node. */
1616
DataFlow::Node getAnUntrustedSource() { UntrustedDataToExternalApiFlow::flow(result, this) }

cpp/ql/src/Security/CWE/CWE-020/ir/ExternalAPIs.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import ExternalAPIsSpecific
1010

1111
/** A node representing untrusted data being passed to an external API. */
1212
class UntrustedExternalApiDataNode extends ExternalApiDataNode {
13-
UntrustedExternalApiDataNode() { UntrustedDataToExternalApiFlow::flow(_, this) }
13+
UntrustedExternalApiDataNode() { UntrustedDataToExternalApiFlow::flowTo(this) }
1414

1515
/** Gets a source of untrusted data which is passed to this external API data node. */
1616
DataFlow::Node getAnUntrustedSource() { UntrustedDataToExternalApiFlow::flow(result, this) }

cpp/ql/src/Security/CWE/CWE-311/CleartextTransmission.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ module FromSensitiveFlow = TaintTracking::Global<FromSensitiveConfig>;
263263
* A taint flow configuration for flow from a sensitive expression to an encryption operation.
264264
*/
265265
module ToEncryptionConfig implements DataFlow::ConfigSig {
266-
predicate isSource(DataFlow::Node source) { FromSensitiveFlow::flow(source, _) }
266+
predicate isSource(DataFlow::Node source) { FromSensitiveFlow::flowFrom(source) }
267267

268268
predicate isSink(DataFlow::Node sink) { isSinkEncrypt(sink, _) }
269269

@@ -311,7 +311,7 @@ where
311311
FromSensitiveFlow::flowPath(source, sink) and
312312
isSinkSendRecv(sink.getNode(), networkSendRecv) and
313313
// no flow from sensitive -> evidence of encryption
314-
not ToEncryptionFlow::flow(source.getNode(), _) and
314+
not ToEncryptionFlow::flowFrom(source.getNode()) and
315315
not FromEncryptionFlow::flowTo(sink.getNode()) and
316316
// construct result
317317
if networkSendRecv instanceof NetworkSend

cpp/ql/src/experimental/Security/CWE/CWE-193/ConstantSizeArrayOffByOne.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ module PointerArithmeticToDerefFlow = DataFlow::Global<PointerArithmeticToDerefC
129129

130130
predicate pointerArithOverflow(PointerArithmeticInstruction pai, int delta) {
131131
pointerArithOverflow0(pai, delta) and
132-
PointerArithmeticToDerefFlow::flow(DataFlow::instructionNode(pai), _)
132+
PointerArithmeticToDerefFlow::flowFrom(DataFlow::instructionNode(pai))
133133
}
134134

135135
bindingset[v]

csharp/autobuilder/Semmle.Autobuild.CSharp/DotNetRule.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public BuildScript Analyse(IAutobuilder<CSharpAutobuildOptions> builder, bool au
4848
{
4949
// When a custom .NET CLI has been installed, `dotnet --info` has already been executed
5050
// to verify the installation.
51-
var ret = dotNetPath is null ? GetInfoCommand(builder.Actions, dotNetPath, environment) : BuildScript.Success;
51+
var ret = dotNetPath is null ? DotNet.InfoScript(builder.Actions, DotNetCommand(builder.Actions, dotNetPath), environment, builder.Logger) : BuildScript.Success;
5252
foreach (var projectOrSolution in builder.ProjectsOrSolutionsToBuild)
5353
{
5454
var cleanCommand = GetCleanCommand(builder.Actions, dotNetPath, environment);
@@ -111,14 +111,6 @@ public static BuildScript WithDotNet(IAutobuilder<AutobuildOptionsShared> builde
111111
private static string DotNetCommand(IBuildActions actions, string? dotNetPath) =>
112112
dotNetPath is not null ? actions.PathCombine(dotNetPath, "dotnet") : "dotnet";
113113

114-
private static BuildScript GetInfoCommand(IBuildActions actions, string? dotNetPath, IDictionary<string, string>? environment)
115-
{
116-
var info = new CommandBuilder(actions, null, environment).
117-
RunCommand(DotNetCommand(actions, dotNetPath)).
118-
Argument("--info");
119-
return info.Script;
120-
}
121-
122114
private static CommandBuilder GetCleanCommand(IBuildActions actions, string? dotNetPath, IDictionary<string, string>? environment)
123115
{
124116
var clean = new CommandBuilder(actions, null, environment).

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNet.cs

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.ObjectModel;
44
using System.IO;
55
using System.Linq;
6+
using System.Threading;
67
using Newtonsoft.Json.Linq;
78

89
using Semmle.Util;
@@ -36,12 +37,29 @@ private DotNet(ILogger logger, string? dotNetPath, TemporaryDirectory tempWorkin
3637

3738
public static IDotNet Make(ILogger logger, string? dotNetPath, TemporaryDirectory tempWorkingDirectory, DependabotProxy? dependabotProxy) => new DotNet(logger, dotNetPath, tempWorkingDirectory, dependabotProxy);
3839

40+
private static void HandleRetryExitCode143(string dotnet, int attempt, ILogger logger)
41+
{
42+
logger.LogWarning($"Running '{dotnet} --info' failed with exit code 143. Retrying...");
43+
var sleep = Math.Pow(2, attempt) * 1000;
44+
Thread.Sleep((int)sleep);
45+
}
46+
3947
private void Info()
4048
{
41-
var res = dotnetCliInvoker.RunCommand("--info", silent: false);
42-
if (!res)
49+
// Allow up to four attempts (with up to three retries) to run `dotnet --info`, to mitigate transient issues
50+
for (int attempt = 0; attempt < 4; attempt++)
4351
{
44-
throw new Exception($"{dotnetCliInvoker.Exec} --info failed.");
52+
var exitCode = dotnetCliInvoker.RunCommandExitCode("--info", silent: false);
53+
switch (exitCode)
54+
{
55+
case 0:
56+
return;
57+
case 143 when attempt < 3:
58+
HandleRetryExitCode143(dotnetCliInvoker.Exec, attempt, logger);
59+
continue;
60+
default:
61+
throw new Exception($"{dotnetCliInvoker.Exec} --info failed with exit code {exitCode}.");
62+
}
4563
}
4664
}
4765

@@ -193,6 +211,35 @@ private static BuildScript DownloadDotNet(IBuildActions actions, ILogger logger,
193211
return BuildScript.Failure;
194212
}
195213

214+
/// <summary>
215+
/// Returns a script for running `dotnet --info`, with retries on exit code 143.
216+
/// </summary>
217+
public static BuildScript InfoScript(IBuildActions actions, string dotnet, IDictionary<string, string>? environment, ILogger logger)
218+
{
219+
var info = new CommandBuilder(actions, null, environment).
220+
RunCommand(dotnet).
221+
Argument("--info");
222+
var script = info.Script;
223+
for (var attempt = 0; attempt < 4; attempt++)
224+
{
225+
var attemptCopy = attempt; // Capture in local variable
226+
script = BuildScript.Bind(script, ret =>
227+
{
228+
switch (ret)
229+
{
230+
case 0:
231+
return BuildScript.Success;
232+
case 143 when attemptCopy < 3:
233+
HandleRetryExitCode143(dotnet, attemptCopy, logger);
234+
return info.Script;
235+
default:
236+
return BuildScript.Failure;
237+
}
238+
});
239+
}
240+
return script;
241+
}
242+
196243
/// <summary>
197244
/// Returns a script for downloading specific .NET SDK versions, if the
198245
/// versions are not already installed.
@@ -292,9 +339,7 @@ BuildScript GetInstall(string pwsh) =>
292339
};
293340
}
294341

295-
var dotnetInfo = new CommandBuilder(actions, environment: MinimalEnvironment).
296-
RunCommand(actions.PathCombine(path, "dotnet")).
297-
Argument("--info").Script;
342+
var dotnetInfo = InfoScript(actions, actions.PathCombine(path, "dotnet"), MinimalEnvironment.ToDictionary(), logger);
298343

299344
Func<string, BuildScript> getInstallAndVerify = version =>
300345
// run `dotnet --info` after install, to check that it executes successfully

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNetCliInvoker.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,21 @@ private ProcessStartInfo MakeDotnetStartInfo(string args, string? workingDirecto
5757
return startInfo;
5858
}
5959

60-
private bool RunCommandAux(string args, string? workingDirectory, out IList<string> output, bool silent)
60+
private int RunCommandExitCodeAux(string args, string? workingDirectory, out IList<string> output, out string dirLog, bool silent)
6161
{
62-
var dirLog = string.IsNullOrWhiteSpace(workingDirectory) ? "" : $" in {workingDirectory}";
62+
dirLog = string.IsNullOrWhiteSpace(workingDirectory) ? "" : $" in {workingDirectory}";
6363
var pi = MakeDotnetStartInfo(args, workingDirectory);
6464
var threadId = Environment.CurrentManagedThreadId;
6565
void onOut(string s) => logger.Log(silent ? Severity.Debug : Severity.Info, s, threadId);
6666
void onError(string s) => logger.LogError(s, threadId);
6767
logger.LogInfo($"Running '{Exec} {args}'{dirLog}");
6868
var exitCode = pi.ReadOutput(out output, onOut, onError);
69+
return exitCode;
70+
}
71+
72+
private bool RunCommandAux(string args, string? workingDirectory, out IList<string> output, bool silent)
73+
{
74+
var exitCode = RunCommandExitCodeAux(args, workingDirectory, out output, out var dirLog, silent);
6975
if (exitCode != 0)
7076
{
7177
logger.LogError($"Command '{Exec} {args}'{dirLog} failed with exit code {exitCode}");
@@ -77,6 +83,9 @@ private bool RunCommandAux(string args, string? workingDirectory, out IList<stri
7783
public bool RunCommand(string args, bool silent = true) =>
7884
RunCommandAux(args, null, out _, silent);
7985

86+
public int RunCommandExitCode(string args, bool silent = true) =>
87+
RunCommandExitCodeAux(args, null, out _, out _, silent);
88+
8089
public bool RunCommand(string args, out IList<string> output, bool silent = true) =>
8190
RunCommandAux(args, null, out output, silent);
8291

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/IDotNetCliInvoker.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ internal interface IDotNetCliInvoker
3030
/// </summary>
3131
bool RunCommand(string args, bool silent = true);
3232

33+
/// <summary>
34+
/// Execute `dotnet <paramref name="args"/>` and return the exit code.
35+
/// If `silent` is true the output of the command is logged as `debug` otherwise as `info`.
36+
/// </summary>
37+
int RunCommandExitCode(string args, bool silent = true);
38+
3339
/// <summary>
3440
/// Execute `dotnet <paramref name="args"/>` and return true if the command succeeded, otherwise false.
3541
/// The output of the command is returned in `output`.

csharp/extractor/Semmle.Extraction.Tests/DotNet.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ internal class DotNetCliInvokerStub : IDotNetCliInvoker
1212
private string lastArgs = "";
1313
public string WorkingDirectory { get; private set; } = "";
1414
public bool Success { get; set; } = true;
15+
public int ExitCode { get; set; } = 0;
1516

1617
public DotNetCliInvokerStub(IList<string> output)
1718
{
@@ -26,6 +27,12 @@ public bool RunCommand(string args, bool silent)
2627
return Success;
2728
}
2829

30+
public int RunCommandExitCode(string args, bool silent)
31+
{
32+
lastArgs = args;
33+
return ExitCode;
34+
}
35+
2936
public bool RunCommand(string args, out IList<string> output, bool silent)
3037
{
3138
lastArgs = args;
@@ -83,7 +90,7 @@ public void TestDotnetInfo()
8390
public void TestDotnetInfoFailure()
8491
{
8592
// Setup
86-
var dotnetCliInvoker = new DotNetCliInvokerStub(new List<string>()) { Success = false };
93+
var dotnetCliInvoker = new DotNetCliInvokerStub(new List<string>()) { ExitCode = 1 };
8794

8895
// Execute
8996
try
@@ -94,7 +101,7 @@ public void TestDotnetInfoFailure()
94101
// Verify
95102
catch (Exception e)
96103
{
97-
Assert.Equal("dotnet --info failed.", e.Message);
104+
Assert.Equal("dotnet --info failed with exit code 1.", e.Message);
98105
return;
99106
}
100107
Assert.Fail("Expected exception");

0 commit comments

Comments
 (0)