duckdb / duckdb/duckdb-java

NUL bytes in SQL statements leads to late errors

Aperta
#34 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
C++
Stelle
127
Fork
80
Merge medio
13h 49m
PR unite (30g)
48

Descrizione

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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia da DuckDBPreparedStatement e riproduci il problema usando l’esempio JDBC con un’istruzione SQL contenente un NUL byte. Determina come viene gestita l’istruzione prima del parsing; il lavoro è completato quando le query non valide contenenti NUL byte ricevono un errore chiaro e immediato, invece dell’errore troncato e fuorviante del parser mostrato qui.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
java, sql
Ambito
databases
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
55/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.