Skip to content

Commit 99bbca8

Browse files
committed
C#: Exclude overrides of Equals and GetHashCode in model generation.
1 parent f480ab9 commit 99bbca8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ private import csharp as CS
66
private import semmle.code.csharp.commons.Util as Util
77
private import semmle.code.csharp.commons.Collections as Collections
88
private import semmle.code.csharp.dataflow.internal.DataFlowDispatch
9+
private import semmle.code.csharp.frameworks.System as System
910
import semmle.code.csharp.dataflow.ExternalFlow as ExternalFlow
1011
import semmle.code.csharp.dataflow.internal.DataFlowImplCommon as DataFlowImplCommon
1112
import semmle.code.csharp.dataflow.internal.DataFlowPrivate as DataFlowPrivate
@@ -16,14 +17,25 @@ module TaintTracking = CS::TaintTracking;
1617

1718
class Type = CS::Type;
1819

20+
/**
21+
* Holds if `api` is an override of `GetHashCode` or `Equals`.
22+
*/
23+
private predicate isIrrellevantObjectOveride(CS::Callable api) {
24+
exists(System::SystemObjectClass c |
25+
api = c.getGetHashCodeMethod().getAnOverrider*() or
26+
api = c.getEqualsMethod().getAnOverrider*()
27+
)
28+
}
29+
1930
/**
2031
* Holds if it is relevant to generate models for `api`.
2132
*/
2233
private predicate isRelevantForModels(CS::Callable api) {
2334
[api.(CS::Modifiable), api.(CS::Accessor).getDeclaration()].isEffectivelyPublic() and
35+
api.getDeclaringType().getNamespace().getQualifiedName() != "" and
2436
not api instanceof CS::ConversionOperator and
2537
not api instanceof Util::MainMethod and
26-
api.getDeclaringType().getNamespace().getQualifiedName() != ""
38+
not isIrrellevantObjectOveride(api)
2739
}
2840

2941
/**

0 commit comments

Comments
 (0)