Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

False Negative: CompareIdenticalValues.ql misses self-comparisons once the same value is routed through aliases or tiny helper methods.

未关闭
#21,535 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
java
领域
security

调研方向

先从 Likely Bugs/Comparison/CompareIdenticalValues.ql 开始,然后检查 PosCase2_Var1.java、PosCase2_Var3.java 和 PosCase3_Var3.java,以了解报告的 alias、辅助方法和重复表达式案例。当 checker 能够将列出的比较识别为冗余或可疑,且不改变无关行为时,工作即完成。

由索引模型根据 Issue 内容生成。

描述

Version
codeql 2.24.3

Checker

  • Checker id: Likely Bugs/Comparison/CompareIdenticalValues.ql
  • Checker description: Detects comparisons where the left and right operands are identical in value, such as comparing the same variable, literal, or structurally equal expressions.

Description of the false negative

All three samples are still comparing a value against itself. The only differences are that the value is first copied through an alias or passed through a helper method that preserves the same expression on both sides.

That should still be enough for Likely Bugs/Comparison/CompareIdenticalValues.ql to report the comparison as redundant or suspicious.

Affected test cases

PosCase2_Var1.java

y != x, ref == obj, and val >= h.value all compare equivalent values. The aliasing changes syntax, not semantics.

// Comparison with identical variable accesses should be flagged as identical operands.
package scensct.var.pos;

public class PosCase2_Var1 {
    public static void main(String[] args) {
        int x = 10;
        int y = x; // alias
        boolean b1 = y != x; // still same variable value
        
        Object obj = new Object();
        Object ref = obj;
        boolean b2 = ref == obj; // same reference
        
        Holder h = new Holder();
        int val = h.value;
        boolean b3 = val >= h.value; // same field value
    }
    
    static class Holder {
        int value = 5;
    }
}
PosCase2_Var3.java

The helper calls receive identical arguments on both sides of the comparison, so the resulting expressions are still identical.

// Comparison with identical variable accesses should be flagged as identical operands.
package scensct.var.pos;

public class PosCase2_Var3 {
    public static void main(String[] args) {
        int x = 10;
        boolean b1 = compareNotEqual(x, x);
        
        Object obj = new Object();
        boolean b2 = compareEqual(obj, obj);
        
        Holder h = new Holder();
        boolean b3 = compareGreaterOrEqual(h.value, h.value);
    }
    
    static boolean compareNotEqual(int a, int b) {
        return a != b;
    }
    
    static boolean compareEqual(Object a, Object b) {
        return a == b;
    }
    
    static boolean compareGreaterOrEqual(int a, int b) {
        return a >= b;
    }
    
    static class Holder {
        int value = 5;
    }
}
PosCase3_Var3.java

Each comparison applies the same pure helper to the same inputs on both sides. That is still a self-comparison.

// Comparison with structurally identical binary expressions should be flagged as identical operands.
package scensct.var.pos;

public class PosCase3_Var3 {
    // Variant 3: Extract identical expressions to a helper method
    private static int addOne(int n) {
        return n + 1;
    }
    private static int multiply(int m, int n) {
        return m * n;
    }
    private static int subtractTwo(int n) {
        return n - 2;
    }
    public static void main(String[] args) {
        int x = 5;
        int a = 2, b = 3;
        boolean b1 = addOne(x) > addOne(x);
        boolean b2 = multiply(a, b) == multiply(a, b);
        boolean b3 = subtractTwo(x) <= subtractTwo(x);
    }
}

Cause analysis

The misses suggest that Likely Bugs/Comparison/CompareIdenticalValues.ql is reasoning mostly at the surface-expression level. Once the same value is routed through a local alias or a small pure helper, the query stops recognizing that both sides of the comparison are still equivalent.

For developers, these are not edge cases. Aliases and tiny wrappers are common, and they do not make a self-comparison any less suspicious.

主要语言
CodeQL
星标
10.1k
派生
2.1k
平均合并
2 天 16 小时
30 天内合并 PR
143

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

github/codeql 的其他 Issue

查看 github/codeql 的全部 Issue

相似的 Issue

更多 Security Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。