Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

False Positive: CloseSql.ql reports a ResultSet that is already scoped by try-with-resources on its parent Statement.

Aperta
#21,533 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
java
Ambito
security

Direzione di ricerca

Inizia leggendo Likely Bugs/Resource Leaks/CloseSql.ql e l'esempio NegCase7_Var3.java. Riproduci il report per lo Statement con alias e verifica come viene tracciata la proprietà delle risorse parent. Il lavoro è completato quando il ResultSet in questo caso non viene più segnalato, mentre le risorse SQL realmente non chiuse continuano a essere coperte.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

question

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.

Lingua principale
CodeQL
Stelle
10.1k
Fork
2.1k
Merge medio
2g 16h
PR unite (30g)
143

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di github/codeql

Tutte le issue di github/codeql

Issue simili

Altre issue su Security

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.