False Positive: CloseSql.ql reports a ResultSet that is already scoped by try-with-resources on its parent Statement.
まだ誰も着手していません。
評価
調査の方向性
まず Likely Bugs/Resource Leaks/CloseSql.ql と NegCase7_Var3.java の例を読んでください。エイリアスされた Statement についてレポートを再現し、親リソースの所有権がどのように追跡されているかを確認してください。このケースの ResultSet が報告されなくなり、実際に閉じられていない SQL リソースについては引き続き検出対象となっていれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- CodeQL
- スター
- 10.1k
- フォーク
- 2.1k
- 平均マージ
- 2日 16時間
- マージ済み PR(30日)
- 143
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
github/codeql のほかの issue
-
agentic-workflows
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
false-positive javascript
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
-
C#: cs/simplifiable-boolean-expression false positive on Nullable<bool> compared with a literal オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
false-positive
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
docToolchain/docToolchain#1705 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
modelcontextprotocol/python-sdk#3566 ·
-
Mend: dependency security vulnerability status: needs triage 🕵️♀️
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
carbon-design-system/ibm-products#9907 ·
-
agent/security hive/hosted-available-lke648397-260827-5n31 security
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
canonical/paas-charm#368 · コメント 1 件 ·