Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NUL bytes in SQL statements leads to late errors #34

Open
vlofgren opened this issue Jun 14, 2024 · 0 comments
Open

NUL bytes in SQL statements leads to late errors #34

vlofgren opened this issue Jun 14, 2024 · 0 comments

Comments

@vlofgren
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant