SQLite

View Ticket
Login
2018-12-22
01:13 Fixed ticket [e6f1f2e3]: REPLACE can insert a default NULL into a NOT NULL column plus 5 other changes (artifact: 84675e85 user: drh)
01:13
Do not all REPLACE to sneak a NULL value into a NOT NULL column. Detect that situation and ABORT instead. Fix for ticket [e6f1f2e34dceeb1ed61531c7e98]. (check-in: db8d1d12 user: drh tags: trunk)
00:10 New ticket [e6f1f2e3] REPLACE can insert a default NULL into a NOT NULL column. (artifact: 317b6a4e user: drh)

Ticket Hash: e6f1f2e34dceeb1ed61531c7e98cbac52c84b9b6
Title: REPLACE can insert a default NULL into a NOT NULL column
Status: Fixed Type: Code_Defect
Severity: Important Priority: Immediate
Subsystem: Unknown Resolution: Fixed
Last Modified: 2018-12-22 01:13:33
Version Found In: 3.26.0
User Comments:
drh added on 2018-12-22 00:10:51:

The REPLACE statement is able to put a NULL value into a NOT NULL column. If the DEFAULT value for a NOT NULL column is NULL, and if you try to insert a NULL, then the inserted NULL is detected and the "REPLACE" algorithm kicks in and substitutes the default value. But if the default is also NULL, the second NULL is never detected. For example:

CREATE TABLE t1(x NOT NULL DEFAULT NULL);
REPLACE INTO t1 DEFAULT VALUES;
SELECT quote(x) FROM t1;

This bug has existed in the code since before SQLite version 3.1.0 (2005-01-21). The problem was detected by the Chromium developers using a fuzzer.