github / github/codeql

False Negative : CloseSql.ql cannot detect bugs in the Try-Catch block.

Abierto
#21,393 2 comentarios 0 reacciones 0 asignados Ver en GitHub
question
Lenguaje dominante
CodeQL
Estrellas
10.1k
Forks
2.1k
Merge medio
2 d 15 h
PR fusionados (30 d)
141

Descripción

**Version**
codeql 2.23.9
**Description of the issue**
When I used java/Likely Bugs/Resource Leaks/CloseSql.ql to check the following code, it correctly reported an issue of improper use of createStatement.
```java

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class PosCase3 {
public void test() throws SQLException {
// Scenario 3: Primary resource assigned
Connection conn = DriverManager.getConnection("url", "user", "pass");
// Secondary created from primary, not assigned, not closed
conn.createStatement(); // [REPORTED LINE]
// Secondary Statement leak -> Positive detection.
}
}

```

However, when using CloseSql.ql to detect the following code, no bug were detected and no bug were reported.

```java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.function.Supplier;
public class PosCase3_Var3 {
public void test() throws SQLException {
// Variant 3: Use Supplier to defer creation, then discard
Connection conn = DriverManager.getConnection("url", "user", "pass");
Supplier supplier = () -> {
try {
return conn.createStatement();
} catch (SQLException e) {
throw new RuntimeException(e);
}
};
supplier.get(); // Statement created and leaked
}
}

```

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Start by reading the Java resource-leak query in CloseSql.ql and compare its handling of the direct createStatement case with the Supplier example's try-catch block. Done means the query reports the discarded Statement created by supplier.get() while preserving the existing detection.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
java
Área
security
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
48/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.