False Positive: CloseSql.ql reports a ResultSet that is already scoped by try-with-resources on its parent Statement.
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 68/100
Direção de pesquisa
Comece lendo Likely Bugs/Resource Leaks/CloseSql.ql e o exemplo NegCase7_Var3.java. Reproduza o relatório para o Statement com alias e inspecione como a propriedade dos recursos pai é rastreada. Considera-se concluído quando o ResultSet neste caso não for mais reportado, enquanto os recursos SQL genuinamente não fechados continuarem cobertos.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Version
codeql 2.24.3
Checker
- Checker id:
Likely Bugs/Resource Leaks/CloseSql.ql - Checker description: This checker detects SQL resource objects (Connection, Statement, ResultSet) that are initialized locally and not guaranteed to be closed on method exit.
Description of the false positive
This case should stay out of the result set. The ResultSet is created from a Statement that is itself managed by try-with-resources, together with the owning Connection. Once the try block exits, both parent resources are closed, and the ResultSet lifetime is covered by that ownership chain.
The alias on the Statement does not change that. It is still the same tracked resource.
Affected test cases
NegCase7_Var3.java
stmtAlias is just another reference to originalStmt. The query appears to lose that alias relationship and treats rs as if it were detached from the try-with-resources scope.
// A locally initialized SQL ResultSet obtained via a method call on a Statement variable, where Statement is a transitive parent closeable resource, should not be flagged as unclosed.
package scensct.var.neg;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
public class NegCase7_Var3 {
public void test() throws Exception {
try (Connection conn = DriverManager.getConnection("jdbc:test");
Statement originalStmt = conn.createStatement()) {
// Alias the Statement
Statement stmtAlias = originalStmt;
// Always-true condition
if (conn != null) {
// Locally initialized ResultSet via method call on aliased Statement
ResultSet rs = stmtAlias.executeQuery("SELECT 1"); // [REPORTED LINE]
}
}
}
}
Cause analysis
Likely Bugs/Resource Leaks/CloseSql.ql is supposed to report SQL resources that are not guaranteed to be closed. That is not what this sample is doing.
The only reason this gets reported is that the Statement is referenced through stmtAlias instead of its original local name. If the query stops recognizing parent-resource ownership after a trivial alias, it will produce noise in ordinary JDBC code where objects are routinely passed through locals before use.
This is an ownership-tracking false positive, not a real leak.
- Linguagem predominante
- CodeQL
- Estrelas
- 10.1k
- Forks
- 2.1k
- Merge médio
- 2d 16h
- PRs com merge (30d)
- 143
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de github/codeql
-
agentic-workflows
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
-
false-positive javascript
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
-
C#: cs/simplifiable-boolean-expression false positive on Nullable<bool> compared with a literal Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
-
false-positive
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
Todas as issues de github/codeql
Issues semelhantes
-
enhancement
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
canonical/paas-charm#368 · 1 comentário ·
-
enhancement
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
palladius/rails8-app-on-gcp#142 ·
-
addition to tracking list Aberta
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 90/100
StevenBlack/hosts#3256 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
corsairdev/corsair#1764 ·
-
oblt-aw/detector/security
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100