Skip to content

Commit c79c9dd

Browse files
committed
C#: Don't generate models for any higher order callables.
1 parent 8726766 commit c79c9dd

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,24 @@ module TaintTracking = CS::TaintTracking;
1717

1818
class Type = CS::Type;
1919

20+
/**
21+
* Holds if any of the parameters of `api` are `System.Func<>`.
22+
*/
23+
private predicate isHigherOrder(CS::Callable api) {
24+
exists(Type t | t = api.getAParameter().getType().getUnboundDeclaration() |
25+
t instanceof System::SystemFuncDelegateType
26+
)
27+
}
28+
2029
/**
2130
* Holds if it is relevant to generate models for `api`.
2231
*/
2332
private predicate isRelevantForModels(CS::Callable api) {
2433
[api.(CS::Modifiable), api.(CS::Accessor).getDeclaration()].isEffectivelyPublic() and
2534
api.getDeclaringType().getNamespace().getQualifiedName() != "" and
2635
not api instanceof CS::ConversionOperator and
27-
not api instanceof Util::MainMethod
36+
not api instanceof Util::MainMethod and
37+
not isHigherOrder(api)
2838
}
2939

3040
/**

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,17 @@ public Int32 M4(Int32 i)
8585
{
8686
return i;
8787
}
88+
}
89+
90+
public class HigherOrderParameters
91+
{
92+
public string M1(string s, Func<string, string> map)
93+
{
94+
return s;
95+
}
96+
97+
public object M2(Func<object, object> map, object o)
98+
{
99+
return map(o);
100+
}
88101
}

0 commit comments

Comments
 (0)