False Positive: IterableIterator.ql reports classes whose `hasNext()` still reliably disables iteration.
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 55/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- java
- 领域
- security, testing-qa
调研方向
从 Language Abuse/IterableIterator.ql checker 以及受影响的 NegCase6_Var2.java 和 NegCase6_Var4.java 测试用例开始。跟踪 hasNext() 通过 helper 或常量返回 false 时是如何被识别的,然后更新 checker 测试,使这些用例不再被报告,同时仍然覆盖不安全的 self-iterable 用例。
由索引模型根据 Issue 内容生成。
描述
False Positive: IterableIterator.ql reports classes whose hasNext() still reliably disables iteration.
Version
codeql 2.24.3
Checker
- Checker id:
Language Abuse/IterableIterator.ql - Checker description: This checker detects classes that implement Iterable by returning themselves as the Iterator but lack a guard to prevent multiple concurrent iterations.
Description of the false positive
These classes do return this from iterator(), but hasNext() still deterministically returns false, which is exactly the built-in guard that keeps iteration from proceeding. The refactoring only changes how that false result is computed.
Affected test cases
NegCase6_Var2.java
hasNext() still disables reuse of the iterator instance in practice, so this should not be reported as an unsafe self-iterable.
// A concrete class that implements Iterable, returns "this" in iterator(), and has hasNext() returning false should not be flagged.
package scensct.var.neg;
import java.util.Iterator;
public class NegCase6_Var2 implements Iterable<Double>, Iterator<Double> { // [REPORTED LINE]
public Iterator<Double> iterator() {
return this;
}
private boolean neverHasNext() {
return false;
}
public boolean hasNext() {
return neverHasNext();
}
public Double next() {
return 0.0;
}
}
NegCase6_Var4.java
The iteration guard is still present even though the control flow is slightly different.
// A concrete class that implements Iterable, returns "this" in iterator(), and has hasNext() returning false should not be flagged.
package scensct.var.neg;
import java.util.Iterator;
public class NegCase6_Var4 implements Iterable<Double>, Iterator<Double> { // [REPORTED LINE]
private final boolean NO_MORE = false;
public Iterator<Double> iterator() {
return this;
}
public boolean hasNext() {
for (int i = 0; i < 1; i++) {
// loop does nothing
}
return NO_MORE;
}
public Double next() {
return 0.0;
}
}
Cause analysis
The query appears too literal about what counts as a valid guard. Once hasNext() returns false via a helper or a constant field instead of a bare literal, the class is still reported.
That is overly rigid. The safety property here is semantic: iteration is disabled, regardless of whether false is returned directly or indirectly.
References
None known.
- 主要语言
- CodeQL
- 星标
- 10.1k
- 派生
- 2.1k
- 平均合并
- 2 天 16 小时
- 30 天内合并 PR
- 143
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
github/codeql 的其他 Issue
-
agentic-workflows
难度 2/5 1-3 小时 新手友好度 70/100
-
false-positive javascript
难度 2/5 1-3 小时 新手友好度 84/100
-
难度 2/5 1-3 小时 新手友好度 82/100
-
难度 2/5 1-3 小时 新手友好度 78/100
-
false-positive
难度 2/5 1-3 小时 新手友好度 70/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
punkpeye/mcp-remote#369 ·
-
Mend: dependency security vulnerability untriaged
难度 1/5 1 小时以内 新手友好度 86/100
-
难度 2/5 1-3 小时 新手友好度 68/100
-
bug
难度 1/5 1 小时以内 新手友好度 90/100
cisagov/vulnrichment#337 ·
-
bug DUP Reservations
难度 2/5 1-3 小时 新手友好度 68/100
bcgov/reserve-rec-public#896 ·