Skip to content

Commit 79871aa

Browse files
authored
Merge pull request github#17687 from michaelnebel/modelgen/removeduplicatedf
C#/Java: Avoid `df` and `dfc` overlap in model generation.
2 parents ed39c46 + 5d4ceee commit 79871aa

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ public DImpl(string s)
639639
public override string Prop { get { return tainted; } }
640640
}
641641

642-
public abstract class BaseContent
642+
public abstract class BaseContent
643643
{
644644
public abstract object GetValue();
645645

@@ -961,3 +961,30 @@ public string ConcatValueOnBase2(string other, Base2 b2)
961961
return other + b2.GetValue();
962962
}
963963
}
964+
965+
public class AvoidDuplicateLifted
966+
{
967+
public class A
968+
{
969+
public object Prop { get; set; }
970+
971+
// contentbased-summary=Models;AvoidDuplicateLifted+A;true;GetValue;();;Argument[this].Property[Models.AvoidDuplicateLifted+A.Prop];ReturnValue;value;dfc-generated
972+
// summary=Models;AvoidDuplicateLifted+A;true;GetValue;();;Argument[this];ReturnValue;taint;df-generated
973+
public virtual object GetValue()
974+
{
975+
return Prop;
976+
}
977+
}
978+
979+
public class B : A
980+
{
981+
private object field;
982+
983+
// No content based summary as field is a dead synthetic field.
984+
// summary=Models;AvoidDuplicateLifted+A;true;GetValue;();;Argument[this];ReturnValue;taint;df-generated
985+
public override object GetValue()
986+
{
987+
return field;
988+
}
989+
}
990+
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,13 @@ module MakeModelGenerator<
881881
string captureMixedFlow(DataFlowSummaryTargetApi api, boolean lift) {
882882
result = ContentSensitive::captureFlow(api, lift)
883883
or
884-
not exists(ContentSensitive::captureFlow(api, _)) and
884+
not exists(DataFlowSummaryTargetApi api0 |
885+
(api0 = api or api.lift() = api0) and
886+
exists(ContentSensitive::captureFlow(api0, false))
887+
or
888+
api0.lift() = api.lift() and
889+
exists(ContentSensitive::captureFlow(api0, true))
890+
) and
885891
result = captureFlow(api) and
886892
lift = true
887893
}
@@ -895,7 +901,8 @@ module MakeModelGenerator<
895901
not exists(DataFlowSummaryTargetApi api0, boolean lift |
896902
exists(captureMixedFlow(api0, lift)) and
897903
(
898-
lift = false and api0 = api
904+
lift = false and
905+
(api0 = api or api0 = api.lift())
899906
or
900907
lift = true and api0.lift() = api.lift()
901908
)

0 commit comments

Comments
 (0)