NUL bytes in SQL statements leads to late errors
- 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.