NUL bytes in SQL statements leads to late errors
- Vorherrschende Sprache
- C++
- Sterne
- 127
- Forks
- 80
- Ø Merge
- 13 Std. 49 Min.
- Gemergte PRs (30 T.)
- 48
Beschreibung
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
```
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
Beginnen Sie in DuckDBPreparedStatement und reproduzieren Sie das Problem anhand des JDBC-Beispiels mit einer SQL-Anweisung, die ein NUL byte enthält. Ermitteln Sie, wie die Anweisung vor dem Parsen behandelt wird; die Aufgabe ist abgeschlossen, wenn ungültige Abfragen mit NUL byte einen klaren, frühzeitigen Fehler erhalten statt des hier gezeigten verwirrenden abgeschnittenen Parserfehlers.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- java, sql
- Bereich
- databases
- Issue-Typ
- Bug
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 55/100