File tree Expand file tree Collapse file tree 2 files changed +35
-33
lines changed
test/query-tests/security/Recursion Expand file tree Collapse file tree 2 files changed +35
-33
lines changed Original file line number Diff line number Diff line change 1313import java
1414import semmle.code.java.dataflow.DataFlow
1515
16+
1617predicate isTestPackage ( RefType referenceType ) {
1718 referenceType .getPackage ( ) .getName ( ) .toLowerCase ( ) .matches ( "%test%" ) or
1819 referenceType .getPackage ( ) .getName ( ) .toLowerCase ( ) .matches ( "%benchmark%" ) or
@@ -25,6 +26,7 @@ class RecursionSource extends MethodCall {
2526 override string toString ( ) {
2627 result = this .getCaller ( ) .toString ( ) + " calls " + this .getCallee ( ) .toString ( )
2728 }
29+
2830}
2931
3032module RecursiveConfig implements DataFlow:: StateConfigSig {
Original file line number Diff line number Diff line change @@ -106,6 +106,39 @@ private boolean someCondition() {
106106 }
107107}
108108
109+ class RecursiveCallNonLinear {
110+ // finding: level0->...->level0
111+ public boolean level0 () {
112+ if (someOtherCondition ()) {
113+ return true ;
114+ }
115+ if (someCondition ()) {
116+ return level1 ();
117+ }
118+ return level2 ();
119+ }
120+ public boolean level1 () {
121+ if (someCondition ()) {
122+ return true ;
123+ }
124+ return level2 ();
125+ }
126+ public boolean level2 () {
127+ if (someCondition ()) {
128+ return level1 ();
129+ }
130+ return level0 ();
131+ }
132+
133+ private boolean someCondition () {
134+ return false ;
135+ }
136+
137+ private boolean someOtherCondition () {
138+ return true ;
139+ }
140+ }
141+
109142class RecursiveCallWronglyLimited {
110143 // finding: recursion is not limited
111144 public boolean directRecursiveNoDepth (int anything , int depth ) {
@@ -172,37 +205,4 @@ public static boolean foo() {
172205 public static boolean bar () {
173206 return true ;
174207 }
175- }
176-
177- class RecursiveCallNonLinear {
178- // finding: level0->...->level0
179- public boolean level0 () {
180- if (someOtherCondition ()) {
181- return true ;
182- }
183- if (someCondition ()) {
184- return level1 ();
185- }
186- return level2 ();
187- }
188- public boolean level1 () {
189- if (someCondition ()) {
190- return true ;
191- }
192- return level2 ();
193- }
194- public boolean level2 () {
195- if (someCondition ()) {
196- return level1 ();
197- }
198- return level0 ();
199- }
200-
201- private boolean someCondition () {
202- return false ;
203- }
204-
205- private boolean someOtherCondition () {
206- return true ;
207- }
208208}
You can’t perform that action at this time.
0 commit comments