Skip to content

Commit e4c26e3

Browse files
committed
Merge branch 'dm/java-recursion' of github.com:trailofbits/codeql-queries into dm/java-recursion
2 parents b505f25 + c3213e4 commit e4c26e3

File tree

2 files changed

+35
-33
lines changed

2 files changed

+35
-33
lines changed

java/src/security/Recursion/Recursion.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java
1414
import semmle.code.java.dataflow.DataFlow
1515

16+
1617
predicate 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

3032
module RecursiveConfig implements DataFlow::StateConfigSig {

java/test/query-tests/security/Recursion/Recursion.java

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff 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+
109142
class 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
}

0 commit comments

Comments
 (0)