Skip to content

Commit dde42a5

Browse files
committed
Merge rc/1.19 into next.
2 parents 02b58a8 + d94e14d commit dde42a5

File tree

18 files changed

+180
-115
lines changed

18 files changed

+180
-115
lines changed

change-notes/1.19/analysis-cpp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
| Cast from `char*` to `wchar_t*` (`cpp/incorrect-string-type-conversion`) | security, external/cwe/cwe-704 | Detects potentially dangerous casts from `char*` to `wchar_t*`. Results are shown on LGTM by default. |
99
| Dead code due to `goto` or `break` statement (`cpp/dead-code-goto`) | maintainability, external/cwe/cwe-561 | Detects dead code following a `goto` or `break` statement. Results are shown on LGTM by default. |
1010
| Inconsistent direction of for loop (`cpp/inconsistent-loop-direction`) | correctness, external/cwe/cwe-835 | Detects `for` loops where the increment and guard condition don't appear to correspond. Results are shown on LGTM by default. |
11-
| Incorrect Not Operator Usage (`cpp/incorrect-not-operator-usage`) | security, external/cwe/cwe-480 | Finds uses of the logical not (`!`) operator that look like they should be bit-wise not (`~`). Results are hidden on LGTM by default. |
11+
| Incorrect 'not' operator usage (`cpp/incorrect-not-operator-usage`) | security, external/cwe/cwe-480 | Finds uses of the logical not (`!`) operator that look like they should be bit-wise not (`~`). Results are hidden on LGTM by default. |
1212
| Non-virtual destructor in base class (`cpp/virtual-destructor`) | reliability, readability, language-features | This query, `NonVirtualDestructorInBaseClass.ql`, is a replacement in LGTM for the query: No virtual destructor (`AV Rule 78.ql`). The new query ignores base classes with non-public destructors since we consider those to be adequately protected. The new version retains the query identifier, `cpp/virtual-destructor`, and results are displayed by default on LGTM. The old query is no longer run on LGTM. |
1313
| `NULL` application name with an unquoted path in call to `CreateProcess` (`cpp/unsafe-create-process-call`) | security, external/cwe/cwe-428 | Finds unsafe uses of the `CreateProcess` function. Results are hidden on LGTM by default. |
1414
| Setting a DACL to `NULL` in a `SECURITY_DESCRIPTOR` (`cpp/unsafe-dacl-security-descriptor`) | security, external/cwe/cwe-732 | Finds code that creates world-writable objects on Windows by setting their DACL to `NULL`. Results are shown on LGTM by default. |

change-notes/1.19/analysis-javascript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ to run queries and explore the data flow in results.
2828
| Replacement of a substring with itself (`js/identity-replacement`) | correctness, security, external/cwe/cwe-116 | Highlights string replacements that replace a string with itself, which usually indicates a mistake. Results shown on LGTM by default. |
2929
| Stored cross-site scripting (`js/stored-xss`) | security, external/cwe/cwe-079, external/cwe/cwe-116 | Highlights uncontrolled stored values flowing into HTML content, indicating a potential violation of [CWE-079](https://cwe.mitre.org/data/definitions/79.html). Results shown on LGTM by default. |
3030
| Unclear precedence of nested operators (`js/unclear-operator-precedence`) | maintainability, correctness, external/cwe/cwe-783 | Highlights nested binary operators whose relative precedence is easy to misunderstand. Results shown on LGTM by default. |
31-
| Unneeded defensive code | correctness, external/cwe/cwe-570, external/cwe/cwe-571 | Highlights locations where defensive code is not needed. Results are shown on LGTM by default. |
31+
| Unneeded defensive code (`js/unneeded-defensive-code`) | correctness, external/cwe/cwe-570, external/cwe/cwe-571 | Highlights locations where defensive code is not needed. Results are shown on LGTM by default. |
3232
| Unsafe dynamic method access (`js/unsafe-dynamic-method-access` ) | security, external/cwe/cwe-094 | Highlights code that invokes a user-controlled method on an object with unsafe methods. Results are shown on LGTM by default. |
3333
| Unvalidated dynamic method access (`js/unvalidated-dynamic-method-call` ) | security, external/cwe/cwe-754 | Highlights code that invokes a user-controlled method without guarding against exceptional circumstances. Results are shown on LGTM by default. |
3434
| Useless assignment to property (`js/useless-assignment-to-property`) | maintainability | Highlights property assignments whose value is always overwritten. Results are shown on LGTM by default. |

cpp/ql/src/Likely Bugs/Likely Typos/IncorrectNotOperatorUsage.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @name Incorrect Not Operator Usage
2+
* @name Incorrect 'not' operator usage
33
* @description Usage of a logical-not (!) operator as an operand for a bit-wise operation.
44
* This commonly indicates the usage of an incorrect operator instead of the bit-wise not (~) operator,
55
* also known as ones' complement operator.

csharp/autobuilder/Semmle.Autobuild.Tests/BuildScripts.cs

Lines changed: 72 additions & 48 deletions
Large diffs are not rendered by default.

csharp/autobuilder/Semmle.Autobuild/AspBuildRule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Semmle.Autobuild
77
/// </summary>
88
class AspBuildRule : IBuildRule
99
{
10-
public BuildScript Analyse(Autobuilder builder)
10+
public BuildScript Analyse(Autobuilder builder, bool auto)
1111
{
1212
var command = new CommandBuilder(builder.Actions).
1313
RunCommand(builder.Actions.PathCombine(builder.SemmleJavaHome, "bin", "java")).

csharp/autobuilder/Semmle.Autobuild/AutobuildOptions.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Linq;
3+
using System.Text.RegularExpressions;
34

45
namespace Semmle.Autobuild
56
{
@@ -37,14 +38,14 @@ public void ReadEnvironment(IBuildActions actions)
3738
{
3839
RootDirectory = actions.GetCurrentDirectory();
3940
VsToolsVersion = actions.GetEnvironmentVariable(prefix + "VSTOOLS_VERSION");
40-
MsBuildArguments = actions.GetEnvironmentVariable(prefix + "MSBUILD_ARGUMENTS");
41+
MsBuildArguments = actions.GetEnvironmentVariable(prefix + "MSBUILD_ARGUMENTS").AsStringWithExpandedEnvVars(actions);
4142
MsBuildPlatform = actions.GetEnvironmentVariable(prefix + "MSBUILD_PLATFORM");
4243
MsBuildConfiguration = actions.GetEnvironmentVariable(prefix + "MSBUILD_CONFIGURATION");
4344
MsBuildTarget = actions.GetEnvironmentVariable(prefix + "MSBUILD_TARGET");
44-
DotNetArguments = actions.GetEnvironmentVariable(prefix + "DOTNET_ARGUMENTS");
45+
DotNetArguments = actions.GetEnvironmentVariable(prefix + "DOTNET_ARGUMENTS").AsStringWithExpandedEnvVars(actions);
4546
DotNetVersion = actions.GetEnvironmentVariable(prefix + "DOTNET_VERSION");
4647
BuildCommand = actions.GetEnvironmentVariable(prefix + "BUILD_COMMAND");
47-
Solution = actions.GetEnvironmentVariable(prefix + "SOLUTION").AsList(new string[0]);
48+
Solution = actions.GetEnvironmentVariable(prefix + "SOLUTION").AsListWithExpandedEnvVars(actions, new string[0]);
4849

4950
IgnoreErrors = actions.GetEnvironmentVariable(prefix + "IGNORE_ERRORS").AsBool("ignore_errors", false);
5051
Buildless = actions.GetEnvironmentVariable(prefix + "BUILDLESS").AsBool("buildless", false);
@@ -92,12 +93,29 @@ public static Language AsLanguage(this string key)
9293
}
9394
}
9495

95-
public static string[] AsList(this string value, string[] defaultValue)
96+
public static string[] AsListWithExpandedEnvVars(this string value, IBuildActions actions, string[] defaultValue)
9697
{
9798
if (value == null)
9899
return defaultValue;
99100

100-
return value.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
101+
return value.
102+
Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).
103+
Select(s => AsStringWithExpandedEnvVars(s, actions)).ToArray();
104+
}
105+
106+
static readonly Regex linuxEnvRegEx = new Regex(@"\$([a-zA-Z_][a-zA-Z_0-9]*)", RegexOptions.Compiled);
107+
108+
public static string AsStringWithExpandedEnvVars(this string value, IBuildActions actions)
109+
{
110+
if (string.IsNullOrEmpty(value))
111+
return value;
112+
113+
// `Environment.ExpandEnvironmentVariables` only works with Windows-style
114+
// environment variables
115+
var windowsStyle = actions.IsWindows()
116+
? value
117+
: linuxEnvRegEx.Replace(value, m => $"%{m.Groups[1].Value}%");
118+
return actions.EnvironmentExpandEnvironmentVariables(windowsStyle);
101119
}
102120
}
103121
}

csharp/autobuilder/Semmle.Autobuild/Autobuilder.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ interface IBuildRule
1616
/// Analyse the files and produce a build script.
1717
/// </summary>
1818
/// <param name="builder">The files and options relating to the build.</param>
19-
BuildScript Analyse(Autobuilder builder);
19+
/// <param name="auto">Whether this build rule is being automatically applied.</param>
20+
BuildScript Analyse(Autobuilder builder, bool auto);
2021
}
2122

2223
/// <summary>
@@ -135,9 +136,9 @@ public Autobuilder(IBuildActions actions, AutobuildOptions options)
135136
foreach (var solution in options.Solution)
136137
{
137138
if (actions.FileExists(solution))
138-
ret.Add(new Solution(this, solution));
139+
ret.Add(new Solution(this, solution, true));
139140
else
140-
Log(Severity.Error, $"The specified solution file {solution} was not found");
141+
Log(Severity.Error, $"The specified project or solution file {solution} was not found");
141142
}
142143
return ret;
143144
}
@@ -172,7 +173,7 @@ IEnumerable<IProjectOrSolution> FindFiles(string extension, Func<string, Project
172173
return ret;
173174

174175
// Then look for `.sln` files
175-
ret = FindFiles(".sln", f => new Solution(this, f))?.ToList();
176+
ret = FindFiles(".sln", f => new Solution(this, f, false))?.ToList();
176177
if (ret != null)
177178
return ret;
178179

@@ -250,17 +251,17 @@ BuildScript CheckExtractorRun(bool warnOnFailure) =>
250251
switch (GetCSharpBuildStrategy())
251252
{
252253
case CSharpBuildStrategy.CustomBuildCommand:
253-
attempt = new BuildCommandRule().Analyse(this) & CheckExtractorRun(true);
254+
attempt = new BuildCommandRule().Analyse(this, false) & CheckExtractorRun(true);
254255
break;
255256
case CSharpBuildStrategy.Buildless:
256257
// No need to check that the extractor has been executed in buildless mode
257-
attempt = new StandaloneBuildRule().Analyse(this);
258+
attempt = new StandaloneBuildRule().Analyse(this, false);
258259
break;
259260
case CSharpBuildStrategy.MSBuild:
260-
attempt = new MsBuildRule().Analyse(this) & CheckExtractorRun(true);
261+
attempt = new MsBuildRule().Analyse(this, false) & CheckExtractorRun(true);
261262
break;
262263
case CSharpBuildStrategy.DotNet:
263-
attempt = new DotNetRule().Analyse(this) & CheckExtractorRun(true);
264+
attempt = new DotNetRule().Analyse(this, false) & CheckExtractorRun(true);
264265
break;
265266
case CSharpBuildStrategy.Auto:
266267
var cleanTrapFolder =
@@ -285,20 +286,20 @@ BuildScript IntermediateAttempt(BuildScript s) =>
285286

286287
attempt =
287288
// First try .NET Core
288-
IntermediateAttempt(new DotNetRule().Analyse(this)) |
289+
IntermediateAttempt(new DotNetRule().Analyse(this, true)) |
289290
// Then MSBuild
290-
(() => IntermediateAttempt(new MsBuildRule().Analyse(this))) |
291+
(() => IntermediateAttempt(new MsBuildRule().Analyse(this, true))) |
291292
// And finally look for a script that might be a build script
292-
(() => new BuildCommandAutoRule().Analyse(this) & CheckExtractorRun(true)) |
293+
(() => new BuildCommandAutoRule().Analyse(this, true) & CheckExtractorRun(true)) |
293294
// All attempts failed: print message
294295
AutobuildFailure();
295296
break;
296297
}
297298

298299
return
299300
attempt &
300-
(() => new AspBuildRule().Analyse(this)) &
301-
(() => new XmlBuildRule().Analyse(this));
301+
(() => new AspBuildRule().Analyse(this, false)) &
302+
(() => new XmlBuildRule().Analyse(this, false));
302303
}
303304

304305
/// <summary>
@@ -337,13 +338,13 @@ enum CSharpBuildStrategy
337338
BuildScript GetCppBuildScript()
338339
{
339340
if (Options.BuildCommand != null)
340-
return new BuildCommandRule().Analyse(this);
341+
return new BuildCommandRule().Analyse(this, false);
341342

342343
return
343344
// First try MSBuild
344-
new MsBuildRule().Analyse(this) |
345+
new MsBuildRule().Analyse(this, true) |
345346
// Then look for a script that might be a build script
346-
(() => new BuildCommandAutoRule().Analyse(this)) |
347+
(() => new BuildCommandAutoRule().Analyse(this, true)) |
347348
// All attempts failed: print message
348349
AutobuildFailure();
349350
}

csharp/autobuilder/Semmle.Autobuild/BuildActions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ public interface IBuildActions
113113
/// Loads the XML document from <paramref name="filename"/>.
114114
/// </summary>
115115
XmlDocument LoadXml(string filename);
116+
117+
/// <summary>
118+
/// Expand all Windows-style environment variables in <paramref name="s"/>,
119+
/// Environment.ExpandEnvironmentVariables()
120+
/// </summary>
121+
string EnvironmentExpandEnvironmentVariables(string s);
116122
}
117123

118124
/// <summary>
@@ -187,6 +193,8 @@ XmlDocument IBuildActions.LoadXml(string filename)
187193

188194
string IBuildActions.GetFullPath(string path) => Path.GetFullPath(path);
189195

196+
public string EnvironmentExpandEnvironmentVariables(string s) => Environment.ExpandEnvironmentVariables(s);
197+
190198
public static readonly IBuildActions Instance = new SystemBuildActions();
191199
}
192200
}

csharp/autobuilder/Semmle.Autobuild/BuildCommandAutoRule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class BuildCommandAutoRule : IBuildRule
2525
"build"
2626
};
2727

28-
public BuildScript Analyse(Autobuilder builder)
28+
public BuildScript Analyse(Autobuilder builder, bool auto)
2929
{
3030
builder.Log(Severity.Info, "Attempting to locate build script");
3131

csharp/autobuilder/Semmle.Autobuild/BuildCommandRule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/// </summary>
66
class BuildCommandRule : IBuildRule
77
{
8-
public BuildScript Analyse(Autobuilder builder)
8+
public BuildScript Analyse(Autobuilder builder, bool auto)
99
{
1010
if (builder.Options.BuildCommand == null)
1111
return BuildScript.Failure;

0 commit comments

Comments
 (0)