Skip to content

Commit 7a39f07

Browse files
committed
Data flow: Add ConfigSig::accessPathLimit
1 parent 35a8e7c commit 7a39f07

File tree

6 files changed

+36
-9
lines changed

6 files changed

+36
-9
lines changed

csharp/ql/lib/semmle/code/csharp/dataflow/internal/ContentDataFlow.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ module Global<ConfigSig ContentConfig> {
109109

110110
DataFlow::FlowFeature getAFeature() { result = ContentConfig::getAFeature() }
111111

112+
predicate accessPathLimit = ContentConfig::accessPathLimit/0;
113+
112114
// needed to record reads/stores inside summarized callables
113115
predicate includeHiddenNodes() { any() }
114116
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ string captureQualifierFlow(TargetApiSpecific api) {
7272
result = ModelPrinting::asValueModel(api, qualifierString(), "ReturnValue")
7373
}
7474

75-
private int accessPathLimit() { result = 2 }
75+
private int accessPathLimit0() { result = 2 }
7676

7777
private newtype TTaintState =
78-
TTaintRead(int n) { n in [0 .. accessPathLimit()] } or
79-
TTaintStore(int n) { n in [1 .. accessPathLimit()] }
78+
TTaintRead(int n) { n in [0 .. accessPathLimit0()] } or
79+
TTaintStore(int n) { n in [1 .. accessPathLimit0()] }
8080

8181
abstract private class TaintState extends TTaintState {
8282
abstract string toString();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ string captureQualifierFlow(TargetApiSpecific api) {
7272
result = ModelPrinting::asValueModel(api, qualifierString(), "ReturnValue")
7373
}
7474

75-
private int accessPathLimit() { result = 2 }
75+
private int accessPathLimit0() { result = 2 }
7676

7777
private newtype TTaintState =
78-
TTaintRead(int n) { n in [0 .. accessPathLimit()] } or
79-
TTaintStore(int n) { n in [1 .. accessPathLimit()] }
78+
TTaintRead(int n) { n in [0 .. accessPathLimit0()] } or
79+
TTaintStore(int n) { n in [1 .. accessPathLimit0()] }
8080

8181
abstract private class TaintState extends TTaintState {
8282
abstract string toString();

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowImpl1.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ deprecated private module Config implements FullStateConfigSig {
285285

286286
int fieldFlowBranchLimit() { result = min(any(Configuration config).fieldFlowBranchLimit()) }
287287

288+
int accessPathLimit() { result = 5 }
289+
288290
FlowFeature getAFeature() { result = any(Configuration config).getAFeature() }
289291

290292
predicate sourceGrouping(Node source, string sourceGroup) {

shared/dataflow/codeql/dataflow/DataFlow.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,9 @@ module Configs<InputSig Lang> {
376376
*/
377377
default int fieldFlowBranchLimit() { result = 2 }
378378

379+
/** Gets the access path limit. */
380+
default int accessPathLimit() { result = Lang::accessPathLimit() }
381+
379382
/**
380383
* Gets a data flow configuration feature to add restrictions to the set of
381384
* valid flow paths.
@@ -495,6 +498,9 @@ module Configs<InputSig Lang> {
495498
*/
496499
default int fieldFlowBranchLimit() { result = 2 }
497500

501+
/** Gets the access path limit. */
502+
default int accessPathLimit() { result = Lang::accessPathLimit() }
503+
498504
/**
499505
* Gets a data flow configuration feature to add restrictions to the set of
500506
* valid flow paths.
@@ -583,6 +589,8 @@ module DataFlowMake<InputSig Lang> {
583589
private module C implements FullStateConfigSig {
584590
import DefaultState<Config>
585591
import Config
592+
593+
predicate accessPathLimit = Config::accessPathLimit/0;
586594
}
587595

588596
import Impl<C>
@@ -599,6 +607,8 @@ module DataFlowMake<InputSig Lang> {
599607
module GlobalWithState<StateConfigSig Config> implements GlobalFlowSig {
600608
private module C implements FullStateConfigSig {
601609
import Config
610+
611+
predicate accessPathLimit = Config::accessPathLimit/0;
602612
}
603613

604614
import Impl<C>

shared/dataflow/codeql/dataflow/internal/DataFlowImpl.qll

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ module MakeImpl<InputSig Lang> {
9393
*/
9494
int fieldFlowBranchLimit();
9595

96+
/** Gets the access path limit. */
97+
int accessPathLimit();
98+
9699
/**
97100
* Gets a data flow configuration feature to add restrictions to the set of
98101
* valid flow paths.
@@ -1328,6 +1331,13 @@ module MakeImpl<InputSig Lang> {
13281331
fwdFlow1(_, _, _, _, _, _, t0, t, ap, _) and t0 != t
13291332
}
13301333

1334+
bindingset[c, t, tail]
1335+
additional Ap apCons(Content c, Typ t, Ap tail) {
1336+
result = Param::apCons(c, t, tail) and
1337+
Config::accessPathLimit() > 0 and
1338+
if tail instanceof ApNil then any() else Config::accessPathLimit() > 1
1339+
}
1340+
13311341
pragma[nomagic]
13321342
private predicate fwdFlow0(
13331343
NodeEx node, FlowState state, Cc cc, ParamNodeOption summaryCtx, TypOption argT,
@@ -3026,11 +3036,11 @@ module MakeImpl<InputSig Lang> {
30263036
} or
30273037
TConsCons(Content c1, DataFlowType t, Content c2, int len) {
30283038
Stage4::consCand(c1, t, TFrontHead(c2)) and
3029-
len in [2 .. accessPathLimit()] and
3039+
len in [2 .. Config::accessPathLimit()] and
30303040
not expensiveLen2unfolding(c1)
30313041
} or
30323042
TCons1(Content c, int len) {
3033-
len in [1 .. accessPathLimit()] and
3043+
len in [1 .. Config::accessPathLimit()] and
30343044
expensiveLen2unfolding(c)
30353045
}
30363046

@@ -3189,7 +3199,10 @@ module MakeImpl<InputSig Lang> {
31893199
Typ getTyp(DataFlowType t) { result = t }
31903200

31913201
bindingset[c, t, tail]
3192-
Ap apCons(Content c, Typ t, Ap tail) { result.isCons(c, t, tail) }
3202+
Ap apCons(Content c, Typ t, Ap tail) {
3203+
result.isCons(c, t, tail) and
3204+
Config::accessPathLimit() > tail.len()
3205+
}
31933206

31943207
class ApHeadContent = Content;
31953208

0 commit comments

Comments
 (0)