Skip to content

Commit 5cb2bd9

Browse files
committed
C#: Exclude IEquatable Equals implementations.
1 parent 02a0cbf commit 5cb2bd9

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

csharp/ql/src/utils/model-generator/internal/CaptureModelsSpecific.qll

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ module TaintTracking = CS::TaintTracking;
1818
class Type = CS::Type;
1919

2020
/**
21-
* Holds if `api` is an override of `GetHashCode` or `Equals`.
21+
* Holds if `api` is an override or an interface implementation that
22+
* is irrelevant to the data flow analysis.
2223
*/
23-
private predicate isIrrellevantObjectOveride(CS::Callable api) {
24+
private predicate isIrrelevantOverrideOrImplementation(CS::Callable api) {
2425
exists(System::SystemObjectClass c |
2526
api = c.getGetHashCodeMethod().getAnOverrider*() or
2627
api = c.getEqualsMethod().getAnOverrider*()
2728
)
29+
or
30+
exists(System::IEquatableEqualsMethod equals | equals = api)
2831
}
2932

3033
/**
@@ -35,7 +38,7 @@ private predicate isRelevantForModels(CS::Callable api) {
3538
api.getDeclaringType().getNamespace().getQualifiedName() != "" and
3639
not api instanceof CS::ConversionOperator and
3740
not api instanceof Util::MainMethod and
38-
not isIrrellevantObjectOveride(api)
41+
not isIrrelevantOverrideOrImplementation(api)
3942
}
4043

4144
/**

csharp/ql/test/utils/model-generator/NoSummaries.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,22 @@ public int ReturnParam(int input)
4242
}
4343
}
4444
}
45+
}
46+
47+
public class EquatableBound : IEquatable<int>
48+
{
49+
public readonly bool tainted;
50+
public bool Equals(int other)
51+
{
52+
return tainted;
53+
}
54+
}
55+
56+
public class EquatableUnBound<T> : IEquatable<T>
57+
{
58+
public readonly bool tainted;
59+
public bool Equals(T? other)
60+
{
61+
return tainted;
62+
}
4563
}

0 commit comments

Comments
 (0)