Skip to content

Commit

Permalink
Merge branch 'dm/java-recursion' of github.com:trailofbits/codeql-que…
Browse files Browse the repository at this point in the history
…ries into dm/java-recursion
  • Loading branch information
DarkaMaul committed Nov 18, 2024
2 parents b505f25 + c3213e4 commit e4c26e3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 33 deletions.
2 changes: 2 additions & 0 deletions java/src/security/Recursion/Recursion.ql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java
import semmle.code.java.dataflow.DataFlow


predicate isTestPackage(RefType referenceType) {
referenceType.getPackage().getName().toLowerCase().matches("%test%") or
referenceType.getPackage().getName().toLowerCase().matches("%benchmark%") or
Expand All @@ -25,6 +26,7 @@ class RecursionSource extends MethodCall {
override string toString() {
result = this.getCaller().toString() + " calls " + this.getCallee().toString()
}

}

module RecursiveConfig implements DataFlow::StateConfigSig {
Expand Down
66 changes: 33 additions & 33 deletions java/test/query-tests/security/Recursion/Recursion.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,39 @@ private boolean someCondition() {
}
}

class RecursiveCallNonLinear {
// finding: level0->...->level0
public boolean level0() {
if (someOtherCondition()) {
return true;
}
if (someCondition()) {
return level1();
}
return level2();
}
public boolean level1() {
if (someCondition()) {
return true;
}
return level2();
}
public boolean level2() {
if (someCondition()) {
return level1();
}
return level0();
}

private boolean someCondition() {
return false;
}

private boolean someOtherCondition() {
return true;
}
}

class RecursiveCallWronglyLimited {
// finding: recursion is not limited
public boolean directRecursiveNoDepth(int anything, int depth) {
Expand Down Expand Up @@ -172,37 +205,4 @@ public static boolean foo() {
public static boolean bar() {
return true;
}
}

class RecursiveCallNonLinear {
// finding: level0->...->level0
public boolean level0() {
if (someOtherCondition()) {
return true;
}
if (someCondition()) {
return level1();
}
return level2();
}
public boolean level1() {
if (someCondition()) {
return true;
}
return level2();
}
public boolean level2() {
if (someCondition()) {
return level1();
}
return level0();
}

private boolean someCondition() {
return false;
}

private boolean someOtherCondition() {
return true;
}
}

0 comments on commit e4c26e3

Please sign in to comment.