Skip to content

Commit 8bfe8fa

Browse files
authored
Merge branch 'main' into d10c/rtjo-language-tests
2 parents f7804e6 + 860ba2e commit 8bfe8fa

File tree

13 files changed

+199
-178
lines changed

13 files changed

+199
-178
lines changed

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

+18-12
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public HashSet<AssemblyLookupLocation> Restore()
109109
if (checkNugetFeedResponsiveness && !CheckFeeds(out explicitFeeds))
110110
{
111111
// todo: we could also check the reachability of the inherited nuget feeds, but to use those in the fallback we would need to handle authentication too.
112-
var unresponsiveMissingPackageLocation = DownloadMissingPackagesFromSpecificFeeds(explicitFeeds);
112+
var unresponsiveMissingPackageLocation = DownloadMissingPackagesFromSpecificFeeds([], explicitFeeds);
113113
return unresponsiveMissingPackageLocation is null
114114
? []
115115
: [unresponsiveMissingPackageLocation];
@@ -166,11 +166,11 @@ public HashSet<AssemblyLookupLocation> Restore()
166166
.ToList();
167167
assemblyLookupLocations.UnionWith(paths.Select(p => new AssemblyLookupLocation(p)));
168168

169-
LogAllUnusedPackages(dependencies);
169+
var usedPackageNames = GetAllUsedPackageDirNames(dependencies);
170170

171171
var missingPackageLocation = checkNugetFeedResponsiveness
172-
? DownloadMissingPackagesFromSpecificFeeds(explicitFeeds)
173-
: DownloadMissingPackages();
172+
? DownloadMissingPackagesFromSpecificFeeds(usedPackageNames, explicitFeeds)
173+
: DownloadMissingPackages(usedPackageNames);
174174

175175
if (missingPackageLocation is not null)
176176
{
@@ -297,21 +297,21 @@ private void RestoreProjects(IEnumerable<string> projects, out ConcurrentBag<Dep
297297
compilationInfoContainer.CompilationInfos.Add(("Failed project restore with package source error", nugetSourceFailures.ToString()));
298298
}
299299

300-
private AssemblyLookupLocation? DownloadMissingPackagesFromSpecificFeeds(HashSet<string>? feedsFromNugetConfigs)
300+
private AssemblyLookupLocation? DownloadMissingPackagesFromSpecificFeeds(IEnumerable<string> usedPackageNames, HashSet<string>? feedsFromNugetConfigs)
301301
{
302302
var reachableFallbackFeeds = GetReachableFallbackNugetFeeds(feedsFromNugetConfigs);
303303
if (reachableFallbackFeeds.Count > 0)
304304
{
305-
return DownloadMissingPackages(fallbackNugetFeeds: reachableFallbackFeeds);
305+
return DownloadMissingPackages(usedPackageNames, fallbackNugetFeeds: reachableFallbackFeeds);
306306
}
307307

308308
logger.LogWarning("Skipping download of missing packages from specific feeds as no fallback Nuget feeds are reachable.");
309309
return null;
310310
}
311311

312-
private AssemblyLookupLocation? DownloadMissingPackages(IEnumerable<string>? fallbackNugetFeeds = null)
312+
private AssemblyLookupLocation? DownloadMissingPackages(IEnumerable<string> usedPackageNames, IEnumerable<string>? fallbackNugetFeeds = null)
313313
{
314-
var alreadyDownloadedPackages = GetRestoredPackageDirectoryNames(PackageDirectory.DirInfo);
314+
var alreadyDownloadedPackages = usedPackageNames.Select(p => p.ToLowerInvariant());
315315
var alreadyDownloadedLegacyPackages = GetRestoredLegacyPackageNames();
316316

317317
var notYetDownloadedPackages = new HashSet<PackageReference>(fileContent.AllPackages);
@@ -418,17 +418,23 @@ private void RestoreProjects(IEnumerable<string> projects, out ConcurrentBag<Dep
418418
return nugetConfig;
419419
}
420420

421-
private void LogAllUnusedPackages(DependencyContainer dependencies)
421+
private IEnumerable<string> GetAllUsedPackageDirNames(DependencyContainer dependencies)
422422
{
423423
var allPackageDirectories = GetAllPackageDirectories();
424424

425425
logger.LogInfo($"Restored {allPackageDirectories.Count} packages");
426426
logger.LogInfo($"Found {dependencies.Packages.Count} packages in project.assets.json files");
427427

428-
allPackageDirectories
429-
.Where(package => !dependencies.Packages.Contains(package))
428+
var usage = allPackageDirectories.Select(package => (package, isUsed: dependencies.Packages.Contains(package)));
429+
430+
usage
431+
.Where(package => !package.isUsed)
430432
.Order()
431-
.ForEach(package => logger.LogDebug($"Unused package: {package}"));
433+
.ForEach(package => logger.LogDebug($"Unused package: {package.package}"));
434+
435+
return usage
436+
.Where(package => package.isUsed)
437+
.Select(package => package.package);
432438
}
433439

434440
private ICollection<string> GetAllPackageDirectories()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Improved dependency resolution in `build-mode: none` extraction to handle failing `dotnet restore` processes that managed to download a subset of the dependencies before the failure.

java/ql/src/Security/CWE/CWE-327/MaybeBrokenCryptoAlgorithm.ql

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ where
2323
sink.getNode().asExpr() = c.getAlgoSpec() and
2424
InsecureCryptoFlow::flowPath(source, sink)
2525
select c, source, sink,
26-
"Cryptographic algorithm $@ may not be secure, consider using a different algorithm.", source,
26+
"Cryptographic algorithm $@ may not be secure. Consider using a different algorithm.", source,
2727
source.getNode().asExpr().(InsecureAlgorithm).getStringValue()

java/ql/test/query-tests/security/CWE-327/semmle/tests/MaybeBrokenCryptoAlgorithm.expected

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ nodes
66
| WeakHashing.java:21:56:21:91 | getProperty(...) | semmle.label | getProperty(...) |
77
subpaths
88
#select
9-
| Test.java:34:21:34:53 | new SecretKeySpec(...) | Test.java:34:48:34:52 | "foo" | Test.java:34:48:34:52 | "foo" | Cryptographic algorithm $@ may not be secure, consider using a different algorithm. | Test.java:34:48:34:52 | "foo" | foo |
10-
| WeakHashing.java:15:29:15:84 | getInstance(...) | WeakHashing.java:15:55:15:83 | getProperty(...) | WeakHashing.java:15:55:15:83 | getProperty(...) | Cryptographic algorithm $@ may not be secure, consider using a different algorithm. | WeakHashing.java:15:55:15:83 | getProperty(...) | MD5 |
11-
| WeakHashing.java:18:30:18:96 | getInstance(...) | WeakHashing.java:18:56:18:95 | getProperty(...) | WeakHashing.java:18:56:18:95 | getProperty(...) | Cryptographic algorithm $@ may not be secure, consider using a different algorithm. | WeakHashing.java:18:56:18:95 | getProperty(...) | MD5 |
12-
| WeakHashing.java:21:30:21:92 | getInstance(...) | WeakHashing.java:21:56:21:91 | getProperty(...) | WeakHashing.java:21:56:21:91 | getProperty(...) | Cryptographic algorithm $@ may not be secure, consider using a different algorithm. | WeakHashing.java:21:56:21:91 | getProperty(...) | MD5 |
9+
| Test.java:34:21:34:53 | new SecretKeySpec(...) | Test.java:34:48:34:52 | "foo" | Test.java:34:48:34:52 | "foo" | Cryptographic algorithm $@ may not be secure. Consider using a different algorithm. | Test.java:34:48:34:52 | "foo" | foo |
10+
| WeakHashing.java:15:29:15:84 | getInstance(...) | WeakHashing.java:15:55:15:83 | getProperty(...) | WeakHashing.java:15:55:15:83 | getProperty(...) | Cryptographic algorithm $@ may not be secure. Consider using a different algorithm. | WeakHashing.java:15:55:15:83 | getProperty(...) | MD5 |
11+
| WeakHashing.java:18:30:18:96 | getInstance(...) | WeakHashing.java:18:56:18:95 | getProperty(...) | WeakHashing.java:18:56:18:95 | getProperty(...) | Cryptographic algorithm $@ may not be secure. Consider using a different algorithm. | WeakHashing.java:18:56:18:95 | getProperty(...) | MD5 |
12+
| WeakHashing.java:21:30:21:92 | getInstance(...) | WeakHashing.java:21:56:21:91 | getProperty(...) | WeakHashing.java:21:56:21:91 | getProperty(...) | Cryptographic algorithm $@ may not be secure. Consider using a different algorithm. | WeakHashing.java:21:56:21:91 | getProperty(...) | MD5 |

rust/ql/lib/codeql/rust/elements/internal/FieldExprImpl.qll

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module Impl {
2323
*/
2424
class FieldExpr extends Generated::FieldExpr {
2525
/** Gets the record field that this access references, if any. */
26-
StructField getStructField() { result = TypeInference::resolveRecordFieldExpr(this) }
26+
StructField getStructField() { result = TypeInference::resolveStructFieldExpr(this) }
2727

2828
/** Gets the tuple field that this access references, if any. */
2929
TupleField getTupleField() { result = TypeInference::resolveTupleFieldExpr(this) }

rust/ql/lib/codeql/rust/elements/internal/StructImpl.qll

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ module Impl {
4343
* Empty structs are considered to use record fields.
4444
*/
4545
pragma[nomagic]
46-
predicate isRecord() { not this.isTuple() }
46+
predicate isStruct() { not this.isTuple() }
4747
}
4848
}

rust/ql/lib/codeql/rust/elements/internal/VariantImpl.qll

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ module Impl {
3838
predicate isTuple() { this.getFieldList() instanceof TupleFieldList }
3939

4040
/**
41-
* Holds if this variant uses record fields.
41+
* Holds if this variant uses struct fields.
4242
*
43-
* Empty variants are considered to use record fields.
43+
* Empty variants are considered to use struct fields.
4444
*/
4545
pragma[nomagic]
46-
predicate isRecord() { not this.isTuple() }
46+
predicate isStruct() { not this.isTuple() }
4747

4848
/** Gets the enum that this variant belongs to. */
4949
Enum getEnum() { this = result.getVariantList().getAVariant() }

rust/ql/lib/codeql/rust/internal/Type.qll

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ abstract class Type extends TType {
2929
pragma[nomagic]
3030
abstract Function getMethod(string name);
3131

32-
/** Gets the record field `name` belonging to this type, if any. */
32+
/** Gets the struct field `name` belonging to this type, if any. */
3333
pragma[nomagic]
3434
abstract StructField getStructField(string name);
3535

rust/ql/lib/codeql/rust/internal/TypeInference.qll

+19-19
Original file line numberDiff line numberDiff line change
@@ -248,24 +248,24 @@ private TypeMention getExplicitTypeArgMention(Path path, TypeParam tp) {
248248
}
249249

250250
/**
251-
* A matching configuration for resolving types of record expressions
251+
* A matching configuration for resolving types of struct expressions
252252
* like `Foo { bar = baz }`.
253253
*/
254254
private module StructExprMatchingInput implements MatchingInputSig {
255255
private newtype TPos =
256256
TFieldPos(string name) { exists(any(Declaration decl).getField(name)) } or
257-
TRecordPos()
257+
TStructPos()
258258

259259
class DeclarationPosition extends TPos {
260260
string asFieldPos() { this = TFieldPos(result) }
261261

262-
predicate isRecordPos() { this = TRecordPos() }
262+
predicate isStructPos() { this = TStructPos() }
263263

264264
string toString() {
265265
result = this.asFieldPos()
266266
or
267-
this.isRecordPos() and
268-
result = "(record)"
267+
this.isStructPos() and
268+
result = "(struct)"
269269
}
270270
}
271271

@@ -286,15 +286,15 @@ private module StructExprMatchingInput implements MatchingInputSig {
286286
result = tp.resolveTypeAt(path)
287287
)
288288
or
289-
// type parameter of the record itself
290-
dpos.isRecordPos() and
289+
// type parameter of the struct itself
290+
dpos.isStructPos() and
291291
result = this.getTypeParameter(_) and
292292
path = TypePath::singleton(result)
293293
}
294294
}
295295

296-
private class RecordStructDecl extends Declaration, Struct {
297-
RecordStructDecl() { this.isRecord() }
296+
private class StructDecl extends Declaration, Struct {
297+
StructDecl() { this.isStruct() }
298298

299299
override TypeParam getATypeParam() { result = this.getGenericParamList().getATypeParam() }
300300

@@ -304,14 +304,14 @@ private module StructExprMatchingInput implements MatchingInputSig {
304304
result = super.getDeclaredType(dpos, path)
305305
or
306306
// type of the struct itself
307-
dpos.isRecordPos() and
307+
dpos.isStructPos() and
308308
path.isEmpty() and
309309
result = TStruct(this)
310310
}
311311
}
312312

313-
private class RecordVariantDecl extends Declaration, Variant {
314-
RecordVariantDecl() { this.isRecord() }
313+
private class StructVariantDecl extends Declaration, Variant {
314+
StructVariantDecl() { this.isStruct() }
315315

316316
Enum getEnum() { result.getVariantList().getAVariant() = this }
317317

@@ -325,7 +325,7 @@ private module StructExprMatchingInput implements MatchingInputSig {
325325
result = super.getDeclaredType(dpos, path)
326326
or
327327
// type of the enum itself
328-
dpos.isRecordPos() and
328+
dpos.isStructPos() and
329329
path.isEmpty() and
330330
result = TEnum(this.getEnum())
331331
}
@@ -342,7 +342,7 @@ private module StructExprMatchingInput implements MatchingInputSig {
342342
result = this.getFieldExpr(apos.asFieldPos()).getExpr()
343343
or
344344
result = this and
345-
apos.isRecordPos()
345+
apos.isStructPos()
346346
}
347347

348348
Type getInferredType(AccessPosition apos, TypePath path) {
@@ -360,8 +360,8 @@ private module StructExprMatchingInput implements MatchingInputSig {
360360
private module StructExprMatching = Matching<StructExprMatchingInput>;
361361

362362
/**
363-
* Gets the type of `n` at `path`, where `n` is either a record expression or
364-
* a field expression of a record expression.
363+
* Gets the type of `n` at `path`, where `n` is either a struct expression or
364+
* a field expression of a struct expression.
365365
*/
366366
pragma[nomagic]
367367
private Type inferStructExprType(AstNode n, TypePath path) {
@@ -777,7 +777,7 @@ private module FieldExprMatchingInput implements MatchingInputSig {
777777

778778
Declaration getTarget() {
779779
// mutual recursion; resolving fields requires resolving types and vice versa
780-
result = [resolveRecordFieldExpr(this).(AstNode), resolveTupleFieldExpr(this)]
780+
result = [resolveStructFieldExpr(this).(AstNode), resolveTupleFieldExpr(this)]
781781
}
782782
}
783783

@@ -921,10 +921,10 @@ private module Cached {
921921
}
922922

923923
/**
924-
* Gets the record field that the field expression `fe` resolves to, if any.
924+
* Gets the struct field that the field expression `fe` resolves to, if any.
925925
*/
926926
cached
927-
StructField resolveRecordFieldExpr(FieldExpr fe) {
927+
StructField resolveStructFieldExpr(FieldExpr fe) {
928928
exists(string name | result = getFieldExprLookupType(fe, name).getStructField(name))
929929
}
930930

rust/ql/test/library-tests/type-inference/main.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ mod type_parameter_bounds {
255255

256256
mod function_trait_bounds {
257257
#[derive(Debug)]
258-
struct MyThing<A> {
259-
a: A,
258+
struct MyThing<T> {
259+
a: T,
260260
}
261261

262262
#[derive(Debug)]
@@ -387,12 +387,12 @@ mod method_supertraits {
387387
#[derive(Debug)]
388388
struct S2;
389389

390-
trait MyTrait1<A> {
391-
fn m1(self) -> A;
390+
trait MyTrait1<Tr1> {
391+
fn m1(self) -> Tr1;
392392
}
393393

394-
trait MyTrait2<A>: MyTrait1<A> {
395-
fn m2(self) -> A
394+
trait MyTrait2<Tr2>: MyTrait1<Tr2> {
395+
fn m2(self) -> Tr2
396396
where
397397
Self: Sized,
398398
{
@@ -404,8 +404,8 @@ mod method_supertraits {
404404
}
405405
}
406406

407-
trait MyTrait3<A>: MyTrait2<MyThing<A>> {
408-
fn m3(self) -> A
407+
trait MyTrait3<Tr3>: MyTrait2<MyThing<Tr3>> {
408+
fn m3(self) -> Tr3
409409
where
410410
Self: Sized,
411411
{

0 commit comments

Comments
 (0)