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
-
enhancement
難度 2/5 1-3 小時 新手友好度 70/100
canonical/paas-charm#368 · 1 則留言 ·
-
enhancement
難度 2/5 1-3 小時 新手友好度 75/100
palladius/rails8-app-on-gcp#142 ·
-
難度 1/5 1 小時以內 新手友好度 90/100
StevenBlack/hosts#3256 ·
-
難度 2/5 1-3 小時 新手友好度 75/100
corsairdev/corsair#1764 ·
-
oblt-aw/detector/security
難度 2/5 1-3 小時 新手友好度 70/100