Skip to content

Commit 55cfbcc

Browse files
committed
C#/Java: Exclude summaries using callbacks in fields, properties and synthetic fields.
1 parent 5c38935 commit 55cfbcc

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

csharp/ql/src/utils/modelgenerator/internal/CaptureModels.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,10 @@ module ModelGeneratorInput implements ModelGeneratorInputSig<Location, CsharpDat
318318
c.isField(_) or c.isSyntheticField(_) or c.isProperty(_)
319319
}
320320

321+
predicate isCallback(DataFlow::ContentSet c) {
322+
c.isDelegateCallArgument(_) or c.isDelegateCallReturn()
323+
}
324+
321325
string getSyntheticName(DataFlow::ContentSet c) {
322326
exists(CS::Field f |
323327
not f.isEffectivelyPublic() and

csharp/ql/test/utils/modelgenerator/dataflow/Summaries.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ public string ReturnField()
6262
{
6363
return tainted;
6464
}
65+
66+
public Func<object, object> MyFunction;
67+
// summary=Models;BasicFlow;false;MapMyFunction;(System.Object);;Argument[0];Argument[this];taint;df-generated
68+
// summary=Models;BasicFlow;false;MapMyFunction;(System.Object);;Argument[this];ReturnValue;taint;df-generated
69+
// No content based flow as MaD doesn't support callback logic in fields and properties.
70+
public object MapMyFunction(object o)
71+
{
72+
return MyFunction(o);
73+
}
6574
}
6675

6776
public class CollectionFlow

java/ql/src/utils/modelgenerator/internal/CaptureModels.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ module ModelGeneratorInput implements ModelGeneratorInputSig<Location, JavaDataF
254254
c instanceof DataFlowUtil::SyntheticFieldContent
255255
}
256256

257+
predicate isCallback(DataFlow::ContentSet c) { none() }
258+
257259
string getSyntheticName(DataFlow::ContentSet c) {
258260
exists(Field f |
259261
not f.isPublic() and

shared/mad/codeql/mad/modelgenerator/internal/ModelGeneratorImpl.qll

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ signature module ModelGeneratorInputSig<LocationSig Location, InputSig<Location>
206206
*/
207207
predicate isField(Lang::ContentSet c);
208208

209+
/**
210+
* Holds if the content set `c` is callback like.
211+
*/
212+
predicate isCallback(Lang::ContentSet c);
213+
209214
/**
210215
* Gets the MaD synthetic name string representation for the content set `c`, if any.
211216
*/
@@ -618,6 +623,20 @@ module MakeModelGenerator<
618623
isField(ap.getAtIndex(_))
619624
}
620625

626+
/**
627+
* Holds if this access path `ap` mentions a callback.
628+
*/
629+
private predicate mentionsCallback(PropagateContentFlow::AccessPath ap) {
630+
isCallback(ap.getAtIndex(_))
631+
}
632+
633+
/**
634+
* Models as Data currently doesn't support callback logic in fields.
635+
*/
636+
private predicate validateAccessPath(PropagateContentFlow::AccessPath ap) {
637+
not (mentionsField(ap) and mentionsCallback(ap))
638+
}
639+
621640
private predicate apiFlow(
622641
DataFlowSummaryTargetApi api, DataFlow::ParameterNode p,
623642
PropagateContentFlow::AccessPath reads, ReturnNodeExt returnNodeExt,
@@ -859,6 +878,8 @@ module MakeModelGenerator<
859878
input = parameterNodeAsContentInput(p) + printReadAccessPath(reads) and
860879
output = getContentOutput(returnNodeExt) + printStoreAccessPath(stores) and
861880
input != output and
881+
validateAccessPath(reads) and
882+
validateAccessPath(stores) and
862883
(
863884
if mentionsField(reads) or mentionsField(stores)
864885
then lift = false and api.isRelevant()

0 commit comments

Comments
 (0)