github / github/codeql

False negative: DoubleCheckedLocking.ql cannot detect scenarios with ternary expressions.

未关闭
#21,395 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
question
主要语言
CodeQL
星标
10.1k
派生
2.1k
平均合并
2 天 15 小时
30 天内合并 PR
141

描述

**Version**
codeql 2.23.9
**Description of the issue**
When I detect the code like this using java/Likely Bugs/Concurrency/DoubleCheckedLocking.ql, the problem is reported normally:
```java

public class PosCase1 {
private Object instance; // Non-volatile field
public Object getInstance() {
if (instance == null) { // First null check
synchronized (this) { // [REPORTED LINE]
if (instance == null) { // Second null check inside synchronized block
instance = new Object(); // Initialization
}
}
}
return instance; // Return after double-checked locking
}
}
```

However, when ternary expressions are introduced into the code, DoubleCheckedLocking.ql fails to detect the problem:
```java
public class PosCase1_Var1 {
private Object instance; // Non-volatile field
public Object getInstance() {
// Use ternary for outer check, but preserve unsafe pattern
return (instance != null) ? instance : createInstance();
}
private Object createInstance() {
synchronized (this) {
if (instance == null) {
instance = new Object();
}
return instance;
}
}
}
```
These two code snippets are semantically identical, only using a ternary expression with some transformations, which is why DoubleCheckedLocking.ql cannot detect the problem.

贡献指南

打开贡献指南

调研方向

Start with java/Likely Bugs/Concurrency/DoubleCheckedLocking.ql and reproduce the two Java snippets from the issue to compare query results. Done means the query reports the unsafe ternary-based double-checked locking scenario while continuing to report the existing direct pattern.

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

评估

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

把新 issue 发到你的邮箱

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