duckdb / duckdb/duckdb-java

NUL bytes in SQL statements leads to late errors

Open
#34 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
127
Forks
80
Avg merge
13h 49m
Merged PRs (30d)
48

Description

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:

```java
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
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.