Skip to content

Commit c3ecae5

Browse files
committed
Data flow: Sync files
1 parent 136c8b5 commit c3ecae5

28 files changed

+648
-640
lines changed

cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImpl.qll

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -923,28 +923,29 @@ private module Stage2 {
923923

924924
ApOption apSome(Ap ap) { result = TBooleanSome(ap) }
925925

926-
class Cc = boolean;
927-
928-
class CcCall extends Cc {
929-
CcCall() { this = true }
926+
class Cc = CallContext;
930927

931-
/** Holds if this call context may be `call`. */
932-
predicate matchesCall(DataFlowCall call) { any() }
933-
}
928+
class CcCall = CallContextCall;
934929

935-
class CcNoCall extends Cc {
936-
CcNoCall() { this = false }
937-
}
930+
class CcNoCall = CallContextNoCall;
938931

939-
Cc ccNone() { result = false }
932+
Cc ccNone() { result instanceof CallContextAny }
940933

941934
private class LocalCc = Unit;
942935

943936
bindingset[call, c, outercc]
944-
private CcCall getCallContextCall(DataFlowCall call, DataFlowCallable c, Cc outercc) { any() }
937+
private CcCall getCallContextCall(DataFlowCall call, DataFlowCallable c, Cc outercc) {
938+
checkCallContextCall(outercc, call, c) and
939+
if recordDataFlowCallSiteDispatch(call, c)
940+
then result = TSpecificCall(call)
941+
else result = TSomeCall()
942+
}
945943

946944
bindingset[call, c, innercc]
947-
private CcNoCall getCallContextReturn(DataFlowCallable c, DataFlowCall call, Cc innercc) { any() }
945+
private CcNoCall getCallContextReturn(DataFlowCallable c, DataFlowCall call, Cc innercc) {
946+
checkCallContextReturn(innercc, c, call) and
947+
if reducedViableImplInReturn(c, call) then result = TReturn(c, call) else result = ccNone()
948+
}
948949

949950
bindingset[node, cc, config]
950951
private LocalCc getLocalCc(NodeEx node, Cc cc, Configuration config) { any() }
@@ -1169,11 +1170,10 @@ private module Stage2 {
11691170
pragma[nomagic]
11701171
private predicate callMayFlowThroughFwd(DataFlowCall call, Configuration config) {
11711172
exists(Ap argAp0, NodeEx out, Cc cc, ApOption argAp, Ap ap |
1172-
fwdFlow(out, pragma[only_bind_into](cc), pragma[only_bind_into](argAp), ap,
1173-
pragma[only_bind_into](config)) and
1173+
fwdFlow(pragma[only_bind_out](out), pragma[only_bind_out](cc), pragma[only_bind_out](argAp),
1174+
pragma[only_bind_out](ap), pragma[only_bind_out](config)) and
11741175
fwdFlowOutFromArg(call, out, argAp0, ap, config) and
1175-
fwdFlowIsEntered(call, pragma[only_bind_into](cc), pragma[only_bind_into](argAp), argAp0,
1176-
pragma[only_bind_into](config))
1176+
fwdFlowIsEntered(call, cc, argAp, argAp0, config)
11771177
)
11781178
}
11791179

@@ -1857,11 +1857,10 @@ private module Stage3 {
18571857
pragma[nomagic]
18581858
private predicate callMayFlowThroughFwd(DataFlowCall call, Configuration config) {
18591859
exists(Ap argAp0, NodeEx out, Cc cc, ApOption argAp, Ap ap |
1860-
fwdFlow(out, pragma[only_bind_into](cc), pragma[only_bind_into](argAp), ap,
1861-
pragma[only_bind_into](config)) and
1860+
fwdFlow(pragma[only_bind_out](out), pragma[only_bind_out](cc), pragma[only_bind_out](argAp),
1861+
pragma[only_bind_out](ap), pragma[only_bind_out](config)) and
18621862
fwdFlowOutFromArg(call, out, argAp0, ap, config) and
1863-
fwdFlowIsEntered(call, pragma[only_bind_into](cc), pragma[only_bind_into](argAp), argAp0,
1864-
pragma[only_bind_into](config))
1863+
fwdFlowIsEntered(call, cc, argAp, argAp0, config)
18651864
)
18661865
}
18671866

@@ -2117,7 +2116,7 @@ private module Stage3 {
21172116
private predicate flowCandSummaryCtx(NodeEx node, AccessPathFront argApf, Configuration config) {
21182117
exists(AccessPathFront apf |
21192118
Stage3::revFlow(node, true, _, apf, config) and
2120-
Stage3::fwdFlow(node, true, TAccessPathFrontSome(argApf), apf, config)
2119+
Stage3::fwdFlow(node, any(Stage3::CcCall ccc), TAccessPathFrontSome(argApf), apf, config)
21212120
)
21222121
}
21232122

@@ -2615,11 +2614,10 @@ private module Stage4 {
26152614
pragma[nomagic]
26162615
private predicate callMayFlowThroughFwd(DataFlowCall call, Configuration config) {
26172616
exists(Ap argAp0, NodeEx out, Cc cc, ApOption argAp, Ap ap |
2618-
fwdFlow(out, pragma[only_bind_into](cc), pragma[only_bind_into](argAp), ap,
2619-
pragma[only_bind_into](config)) and
2617+
fwdFlow(pragma[only_bind_out](out), pragma[only_bind_out](cc), pragma[only_bind_out](argAp),
2618+
pragma[only_bind_out](ap), pragma[only_bind_out](config)) and
26202619
fwdFlowOutFromArg(call, out, argAp0, ap, config) and
2621-
fwdFlowIsEntered(call, pragma[only_bind_into](cc), pragma[only_bind_into](argAp), argAp0,
2622-
pragma[only_bind_into](config))
2620+
fwdFlowIsEntered(call, cc, argAp, argAp0, config)
26232621
)
26242622
}
26252623

cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImpl2.qll

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -923,28 +923,29 @@ private module Stage2 {
923923

924924
ApOption apSome(Ap ap) { result = TBooleanSome(ap) }
925925

926-
class Cc = boolean;
927-
928-
class CcCall extends Cc {
929-
CcCall() { this = true }
926+
class Cc = CallContext;
930927

931-
/** Holds if this call context may be `call`. */
932-
predicate matchesCall(DataFlowCall call) { any() }
933-
}
928+
class CcCall = CallContextCall;
934929

935-
class CcNoCall extends Cc {
936-
CcNoCall() { this = false }
937-
}
930+
class CcNoCall = CallContextNoCall;
938931

939-
Cc ccNone() { result = false }
932+
Cc ccNone() { result instanceof CallContextAny }
940933

941934
private class LocalCc = Unit;
942935

943936
bindingset[call, c, outercc]
944-
private CcCall getCallContextCall(DataFlowCall call, DataFlowCallable c, Cc outercc) { any() }
937+
private CcCall getCallContextCall(DataFlowCall call, DataFlowCallable c, Cc outercc) {
938+
checkCallContextCall(outercc, call, c) and
939+
if recordDataFlowCallSiteDispatch(call, c)
940+
then result = TSpecificCall(call)
941+
else result = TSomeCall()
942+
}
945943

946944
bindingset[call, c, innercc]
947-
private CcNoCall getCallContextReturn(DataFlowCallable c, DataFlowCall call, Cc innercc) { any() }
945+
private CcNoCall getCallContextReturn(DataFlowCallable c, DataFlowCall call, Cc innercc) {
946+
checkCallContextReturn(innercc, c, call) and
947+
if reducedViableImplInReturn(c, call) then result = TReturn(c, call) else result = ccNone()
948+
}
948949

949950
bindingset[node, cc, config]
950951
private LocalCc getLocalCc(NodeEx node, Cc cc, Configuration config) { any() }
@@ -1169,11 +1170,10 @@ private module Stage2 {
11691170
pragma[nomagic]
11701171
private predicate callMayFlowThroughFwd(DataFlowCall call, Configuration config) {
11711172
exists(Ap argAp0, NodeEx out, Cc cc, ApOption argAp, Ap ap |
1172-
fwdFlow(out, pragma[only_bind_into](cc), pragma[only_bind_into](argAp), ap,
1173-
pragma[only_bind_into](config)) and
1173+
fwdFlow(pragma[only_bind_out](out), pragma[only_bind_out](cc), pragma[only_bind_out](argAp),
1174+
pragma[only_bind_out](ap), pragma[only_bind_out](config)) and
11741175
fwdFlowOutFromArg(call, out, argAp0, ap, config) and
1175-
fwdFlowIsEntered(call, pragma[only_bind_into](cc), pragma[only_bind_into](argAp), argAp0,
1176-
pragma[only_bind_into](config))
1176+
fwdFlowIsEntered(call, cc, argAp, argAp0, config)
11771177
)
11781178
}
11791179

@@ -1857,11 +1857,10 @@ private module Stage3 {
18571857
pragma[nomagic]
18581858
private predicate callMayFlowThroughFwd(DataFlowCall call, Configuration config) {
18591859
exists(Ap argAp0, NodeEx out, Cc cc, ApOption argAp, Ap ap |
1860-
fwdFlow(out, pragma[only_bind_into](cc), pragma[only_bind_into](argAp), ap,
1861-
pragma[only_bind_into](config)) and
1860+
fwdFlow(pragma[only_bind_out](out), pragma[only_bind_out](cc), pragma[only_bind_out](argAp),
1861+
pragma[only_bind_out](ap), pragma[only_bind_out](config)) and
18621862
fwdFlowOutFromArg(call, out, argAp0, ap, config) and
1863-
fwdFlowIsEntered(call, pragma[only_bind_into](cc), pragma[only_bind_into](argAp), argAp0,
1864-
pragma[only_bind_into](config))
1863+
fwdFlowIsEntered(call, cc, argAp, argAp0, config)
18651864
)
18661865
}
18671866

@@ -2117,7 +2116,7 @@ private module Stage3 {
21172116
private predicate flowCandSummaryCtx(NodeEx node, AccessPathFront argApf, Configuration config) {
21182117
exists(AccessPathFront apf |
21192118
Stage3::revFlow(node, true, _, apf, config) and
2120-
Stage3::fwdFlow(node, true, TAccessPathFrontSome(argApf), apf, config)
2119+
Stage3::fwdFlow(node, any(Stage3::CcCall ccc), TAccessPathFrontSome(argApf), apf, config)
21212120
)
21222121
}
21232122

@@ -2615,11 +2614,10 @@ private module Stage4 {
26152614
pragma[nomagic]
26162615
private predicate callMayFlowThroughFwd(DataFlowCall call, Configuration config) {
26172616
exists(Ap argAp0, NodeEx out, Cc cc, ApOption argAp, Ap ap |
2618-
fwdFlow(out, pragma[only_bind_into](cc), pragma[only_bind_into](argAp), ap,
2619-
pragma[only_bind_into](config)) and
2617+
fwdFlow(pragma[only_bind_out](out), pragma[only_bind_out](cc), pragma[only_bind_out](argAp),
2618+
pragma[only_bind_out](ap), pragma[only_bind_out](config)) and
26202619
fwdFlowOutFromArg(call, out, argAp0, ap, config) and
2621-
fwdFlowIsEntered(call, pragma[only_bind_into](cc), pragma[only_bind_into](argAp), argAp0,
2622-
pragma[only_bind_into](config))
2620+
fwdFlowIsEntered(call, cc, argAp, argAp0, config)
26232621
)
26242622
}
26252623

cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImpl3.qll

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -923,28 +923,29 @@ private module Stage2 {
923923

924924
ApOption apSome(Ap ap) { result = TBooleanSome(ap) }
925925

926-
class Cc = boolean;
927-
928-
class CcCall extends Cc {
929-
CcCall() { this = true }
926+
class Cc = CallContext;
930927

931-
/** Holds if this call context may be `call`. */
932-
predicate matchesCall(DataFlowCall call) { any() }
933-
}
928+
class CcCall = CallContextCall;
934929

935-
class CcNoCall extends Cc {
936-
CcNoCall() { this = false }
937-
}
930+
class CcNoCall = CallContextNoCall;
938931

939-
Cc ccNone() { result = false }
932+
Cc ccNone() { result instanceof CallContextAny }
940933

941934
private class LocalCc = Unit;
942935

943936
bindingset[call, c, outercc]
944-
private CcCall getCallContextCall(DataFlowCall call, DataFlowCallable c, Cc outercc) { any() }
937+
private CcCall getCallContextCall(DataFlowCall call, DataFlowCallable c, Cc outercc) {
938+
checkCallContextCall(outercc, call, c) and
939+
if recordDataFlowCallSiteDispatch(call, c)
940+
then result = TSpecificCall(call)
941+
else result = TSomeCall()
942+
}
945943

946944
bindingset[call, c, innercc]
947-
private CcNoCall getCallContextReturn(DataFlowCallable c, DataFlowCall call, Cc innercc) { any() }
945+
private CcNoCall getCallContextReturn(DataFlowCallable c, DataFlowCall call, Cc innercc) {
946+
checkCallContextReturn(innercc, c, call) and
947+
if reducedViableImplInReturn(c, call) then result = TReturn(c, call) else result = ccNone()
948+
}
948949

949950
bindingset[node, cc, config]
950951
private LocalCc getLocalCc(NodeEx node, Cc cc, Configuration config) { any() }
@@ -1169,11 +1170,10 @@ private module Stage2 {
11691170
pragma[nomagic]
11701171
private predicate callMayFlowThroughFwd(DataFlowCall call, Configuration config) {
11711172
exists(Ap argAp0, NodeEx out, Cc cc, ApOption argAp, Ap ap |
1172-
fwdFlow(out, pragma[only_bind_into](cc), pragma[only_bind_into](argAp), ap,
1173-
pragma[only_bind_into](config)) and
1173+
fwdFlow(pragma[only_bind_out](out), pragma[only_bind_out](cc), pragma[only_bind_out](argAp),
1174+
pragma[only_bind_out](ap), pragma[only_bind_out](config)) and
11741175
fwdFlowOutFromArg(call, out, argAp0, ap, config) and
1175-
fwdFlowIsEntered(call, pragma[only_bind_into](cc), pragma[only_bind_into](argAp), argAp0,
1176-
pragma[only_bind_into](config))
1176+
fwdFlowIsEntered(call, cc, argAp, argAp0, config)
11771177
)
11781178
}
11791179

@@ -1857,11 +1857,10 @@ private module Stage3 {
18571857
pragma[nomagic]
18581858
private predicate callMayFlowThroughFwd(DataFlowCall call, Configuration config) {
18591859
exists(Ap argAp0, NodeEx out, Cc cc, ApOption argAp, Ap ap |
1860-
fwdFlow(out, pragma[only_bind_into](cc), pragma[only_bind_into](argAp), ap,
1861-
pragma[only_bind_into](config)) and
1860+
fwdFlow(pragma[only_bind_out](out), pragma[only_bind_out](cc), pragma[only_bind_out](argAp),
1861+
pragma[only_bind_out](ap), pragma[only_bind_out](config)) and
18621862
fwdFlowOutFromArg(call, out, argAp0, ap, config) and
1863-
fwdFlowIsEntered(call, pragma[only_bind_into](cc), pragma[only_bind_into](argAp), argAp0,
1864-
pragma[only_bind_into](config))
1863+
fwdFlowIsEntered(call, cc, argAp, argAp0, config)
18651864
)
18661865
}
18671866

@@ -2117,7 +2116,7 @@ private module Stage3 {
21172116
private predicate flowCandSummaryCtx(NodeEx node, AccessPathFront argApf, Configuration config) {
21182117
exists(AccessPathFront apf |
21192118
Stage3::revFlow(node, true, _, apf, config) and
2120-
Stage3::fwdFlow(node, true, TAccessPathFrontSome(argApf), apf, config)
2119+
Stage3::fwdFlow(node, any(Stage3::CcCall ccc), TAccessPathFrontSome(argApf), apf, config)
21212120
)
21222121
}
21232122

@@ -2615,11 +2614,10 @@ private module Stage4 {
26152614
pragma[nomagic]
26162615
private predicate callMayFlowThroughFwd(DataFlowCall call, Configuration config) {
26172616
exists(Ap argAp0, NodeEx out, Cc cc, ApOption argAp, Ap ap |
2618-
fwdFlow(out, pragma[only_bind_into](cc), pragma[only_bind_into](argAp), ap,
2619-
pragma[only_bind_into](config)) and
2617+
fwdFlow(pragma[only_bind_out](out), pragma[only_bind_out](cc), pragma[only_bind_out](argAp),
2618+
pragma[only_bind_out](ap), pragma[only_bind_out](config)) and
26202619
fwdFlowOutFromArg(call, out, argAp0, ap, config) and
2621-
fwdFlowIsEntered(call, pragma[only_bind_into](cc), pragma[only_bind_into](argAp), argAp0,
2622-
pragma[only_bind_into](config))
2620+
fwdFlowIsEntered(call, cc, argAp, argAp0, config)
26232621
)
26242622
}
26252623

cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImpl4.qll

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -923,28 +923,29 @@ private module Stage2 {
923923

924924
ApOption apSome(Ap ap) { result = TBooleanSome(ap) }
925925

926-
class Cc = boolean;
927-
928-
class CcCall extends Cc {
929-
CcCall() { this = true }
926+
class Cc = CallContext;
930927

931-
/** Holds if this call context may be `call`. */
932-
predicate matchesCall(DataFlowCall call) { any() }
933-
}
928+
class CcCall = CallContextCall;
934929

935-
class CcNoCall extends Cc {
936-
CcNoCall() { this = false }
937-
}
930+
class CcNoCall = CallContextNoCall;
938931

939-
Cc ccNone() { result = false }
932+
Cc ccNone() { result instanceof CallContextAny }
940933

941934
private class LocalCc = Unit;
942935

943936
bindingset[call, c, outercc]
944-
private CcCall getCallContextCall(DataFlowCall call, DataFlowCallable c, Cc outercc) { any() }
937+
private CcCall getCallContextCall(DataFlowCall call, DataFlowCallable c, Cc outercc) {
938+
checkCallContextCall(outercc, call, c) and
939+
if recordDataFlowCallSiteDispatch(call, c)
940+
then result = TSpecificCall(call)
941+
else result = TSomeCall()
942+
}
945943

946944
bindingset[call, c, innercc]
947-
private CcNoCall getCallContextReturn(DataFlowCallable c, DataFlowCall call, Cc innercc) { any() }
945+
private CcNoCall getCallContextReturn(DataFlowCallable c, DataFlowCall call, Cc innercc) {
946+
checkCallContextReturn(innercc, c, call) and
947+
if reducedViableImplInReturn(c, call) then result = TReturn(c, call) else result = ccNone()
948+
}
948949

949950
bindingset[node, cc, config]
950951
private LocalCc getLocalCc(NodeEx node, Cc cc, Configuration config) { any() }
@@ -1169,11 +1170,10 @@ private module Stage2 {
11691170
pragma[nomagic]
11701171
private predicate callMayFlowThroughFwd(DataFlowCall call, Configuration config) {
11711172
exists(Ap argAp0, NodeEx out, Cc cc, ApOption argAp, Ap ap |
1172-
fwdFlow(out, pragma[only_bind_into](cc), pragma[only_bind_into](argAp), ap,
1173-
pragma[only_bind_into](config)) and
1173+
fwdFlow(pragma[only_bind_out](out), pragma[only_bind_out](cc), pragma[only_bind_out](argAp),
1174+
pragma[only_bind_out](ap), pragma[only_bind_out](config)) and
11741175
fwdFlowOutFromArg(call, out, argAp0, ap, config) and
1175-
fwdFlowIsEntered(call, pragma[only_bind_into](cc), pragma[only_bind_into](argAp), argAp0,
1176-
pragma[only_bind_into](config))
1176+
fwdFlowIsEntered(call, cc, argAp, argAp0, config)
11771177
)
11781178
}
11791179

@@ -1857,11 +1857,10 @@ private module Stage3 {
18571857
pragma[nomagic]
18581858
private predicate callMayFlowThroughFwd(DataFlowCall call, Configuration config) {
18591859
exists(Ap argAp0, NodeEx out, Cc cc, ApOption argAp, Ap ap |
1860-
fwdFlow(out, pragma[only_bind_into](cc), pragma[only_bind_into](argAp), ap,
1861-
pragma[only_bind_into](config)) and
1860+
fwdFlow(pragma[only_bind_out](out), pragma[only_bind_out](cc), pragma[only_bind_out](argAp),
1861+
pragma[only_bind_out](ap), pragma[only_bind_out](config)) and
18621862
fwdFlowOutFromArg(call, out, argAp0, ap, config) and
1863-
fwdFlowIsEntered(call, pragma[only_bind_into](cc), pragma[only_bind_into](argAp), argAp0,
1864-
pragma[only_bind_into](config))
1863+
fwdFlowIsEntered(call, cc, argAp, argAp0, config)
18651864
)
18661865
}
18671866

@@ -2117,7 +2116,7 @@ private module Stage3 {
21172116
private predicate flowCandSummaryCtx(NodeEx node, AccessPathFront argApf, Configuration config) {
21182117
exists(AccessPathFront apf |
21192118
Stage3::revFlow(node, true, _, apf, config) and
2120-
Stage3::fwdFlow(node, true, TAccessPathFrontSome(argApf), apf, config)
2119+
Stage3::fwdFlow(node, any(Stage3::CcCall ccc), TAccessPathFrontSome(argApf), apf, config)
21212120
)
21222121
}
21232122

@@ -2615,11 +2614,10 @@ private module Stage4 {
26152614
pragma[nomagic]
26162615
private predicate callMayFlowThroughFwd(DataFlowCall call, Configuration config) {
26172616
exists(Ap argAp0, NodeEx out, Cc cc, ApOption argAp, Ap ap |
2618-
fwdFlow(out, pragma[only_bind_into](cc), pragma[only_bind_into](argAp), ap,
2619-
pragma[only_bind_into](config)) and
2617+
fwdFlow(pragma[only_bind_out](out), pragma[only_bind_out](cc), pragma[only_bind_out](argAp),
2618+
pragma[only_bind_out](ap), pragma[only_bind_out](config)) and
26202619
fwdFlowOutFromArg(call, out, argAp0, ap, config) and
2621-
fwdFlowIsEntered(call, pragma[only_bind_into](cc), pragma[only_bind_into](argAp), argAp0,
2622-
pragma[only_bind_into](config))
2620+
fwdFlowIsEntered(call, cc, argAp, argAp0, config)
26232621
)
26242622
}
26252623

0 commit comments

Comments
 (0)