NUL bytes in SQL statements leads to late errors

未關閉
#34 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
55/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
java, sql
領域
databases

研究方向

從 DuckDBPreparedStatement 開始,使用包含 NUL byte 的 SQL 陳述式透過 JDBC 範例重現此問題。確定陳述式在剖析前是如何被處理的;完成標準是,包含 NUL byte 的無效查詢能收到清楚且及早回報的錯誤,而不是此處顯示的令人困惑的截斷剖析器錯誤。

由索引模型根據 Issue 內容生成。

描述

The way the jdbc driver handles un-escaped NUL bytes in a SQL statement means they are ostensibly converted to a C-style string and truncated at the NUL.

While it can be argued this is malformed input and user error, and fine as it is, the error messages are needlessly confusing, and it's possibly an unnecessary attack surface for SQL injections.

If it's true that un-escaped NUL bytes in queries are never valid, it may be preferable to validate the query in DuckDBPreparedStatement, which ought to be a very cheap operation.

Steps to reproduce:

try (var dbConn = DriverManager.getConnection("jdbc:duckdb:");
      var stmt = dbConn.createStatement();
) {
  stmt.execute("SELECT 'a\0b'");
}
catch (SQLException ex)  {
  ex.printStackTrace();
}
java.sql.SQLException: Parser Error: unterminated quoted string at or near "'a"
LINE 1: SELECT 'a
               ^
java.sql.SQLException: java.sql.SQLException: Parser Error: unterminated quoted string at or near "'a"
LINE 1: SELECT 'a
主要語言
C++
星號
129
分支
90
平均合併
5 小時 34 分鐘
30 天內合併 PR
56

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

duckdb/duckdb-java 的其他 Issue

查看 duckdb/duckdb-java 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。