False Negative: CompareIdenticalValues.ql misses self-comparisons once the same value is routed through aliases or tiny helper methods.
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 48/100
Piste de recherche
Commencez par Likely Bugs/Comparison/CompareIdenticalValues.ql, puis examinez PosCase2_Var1.java, PosCase2_Var3.java et PosCase3_Var3.java afin de comprendre les cas signalés d’alias, de méthodes auxiliaires et d’expressions répétées. Le travail est terminé lorsque le checker reconnaît les comparaisons indiquées comme redondantes ou suspectes sans modifier les autres comportements.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- CodeQL
- Étoiles
- 10.1k
- Forks
- 2.1k
- Merge moyen
- 2 j 16 h
- PR mergées (30 j)
- 143
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de github/codeql
-
agentic-workflows
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
-
false-positive javascript
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
-
C#: cs/simplifiable-boolean-expression false positive on Nullable<bool> compared with a literal Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
false-positive
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
Toutes les issues de github/codeql
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
punkpeye/mcp-remote#369 ·
-
Mend: dependency security vulnerability untriaged
Difficulté 1/5 Moins d'une heure Accessibilité débutants 86/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
-
CVE-2024-24786 CPE mismatch Ouvertebug
Difficulté 1/5 Moins d'une heure Accessibilité débutants 90/100
cisagov/vulnrichment#337 ·
-
bug DUP Reservations
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
bcgov/reserve-rec-public#896 ·