Commit Graph

21323 Commits

Author SHA1 Message Date
dan
394aa710f2 Fix a potential problem with ALTER TABLE commands on schemas that contains a triggers or view featuring a sub-query that uses an ON clause with a join that is not a LEFT JOIN.
FossilOrigin-Name: 365dd8b663d5a28af33556b2b3820c6b5482114ef741a1d82b55c6e154f3043a
2019-12-20 14:18:29 +00:00
drh
b2ab3dcff0 Fix harmless compiler warnings.
FossilOrigin-Name: 2bbd014c900e0d71fd30ec647739b82c5dc3aa237a0203f5a1db50593dae199e
2019-12-20 14:08:34 +00:00
dan
73b21382d4 Ensure fts5 consistently calls sqlite3_value_text() before sqlite3_value_bytes(). This matters when storing blobs in fts5 tables within utf-16 databases. Fix for [cf36cb4e02].
FossilOrigin-Name: c16305eba0eb14368f2631b9a82b7eb4483c93f3b31257ee7c33f9b00c344379
2019-12-20 13:24:11 +00:00
drh
1548d5276f Do not continue an ALTER TABLE tree walk of a subquery if a prior error
is seen in the tree.  Report the problem immediately, without continuing.

FossilOrigin-Name: 01ca865f31c0c817ede7f357401ef76cf311ae662397908464f53e1c147f5b6b
2019-12-20 12:55:21 +00:00
drh
0e5ce8029d Fix an assert() in btree.c that can fail if an INSERT is attempted on
a corrupted database while in PRAGMA writable_schema=ON.

FossilOrigin-Name: 07beb3629e648e7feae4e786191514339ac1d8f6ba5bb6e7cc8a04bc1f1cd6ab
2019-12-20 12:33:17 +00:00
drh
8428b3b437 Continuation of [e2bddcd4c55ba3cb]: Add another spot where it is necessary
to abort early due to prior errors in sqlite3WindowRewrite().

FossilOrigin-Name: cba2a2a44cdf138a629109bb0ad088ed4ef67fc66bed3e0373554681a39615d2
2019-12-19 22:08:19 +00:00
drh
6ad0e25fa4 Fix the regexp extension so that it correctly translates all over-length
3-byte UTF8 sequences into 0xfffd.

FossilOrigin-Name: 3d4c0bf8904135fa68c75801bfa738715cacc3b19dc8ad6ef550b11798d4b121
2019-12-19 21:11:48 +00:00
drh
8654186b02 When an error occurs while rewriting the parser tree for window functions
in the sqlite3WindowRewrite() routine, make sure that pParse->nErr is set,
and make sure that this shuts down any subsequent code generation that might
depend on the transformations that were implemented.  This fixes a problem
discovered by the Yongheng and Rui fuzzer.

FossilOrigin-Name: e2bddcd4c55ba3cbe0130332679ff4b048630d0ced9a8899982edb5a3569ba7f
2019-12-19 20:37:32 +00:00
drh
34ab941e5b Detect the invalid use of NULLS LAST on an INTEGER PRIMARY KEY definition
of a WITHOUT ROWID table.

FossilOrigin-Name: 4417c5bf0aabb34ed174f01afd981c924ae965a42128719d8d6735536631d12f
2019-12-19 17:42:27 +00:00
drh
54d501092d Fix the zipfile extension so that INSERT works even if the pathname of
the file being inserted is a NULL.  Bug discovered by the
Yongheng and Rui fuzzer.

FossilOrigin-Name: a80f84b511231204658304226de3e075a55afc2e3f39ac063716f7a57f585c06
2019-12-19 15:15:40 +00:00
drh
59c5679691 Fix incorrect SQL generated by the Lemon change of the previous check-in.
FossilOrigin-Name: fccfb8a9ed3c1df9f23762bb8df6fdf36a21118899e3fae41f451169a5f2c08e
2019-12-19 13:17:07 +00:00
drh
3e5f7fef33 Modify the parse.sql output file from Lemon so that the RULE table contains
a column with the complete text of the rule.

FossilOrigin-Name: 329cbb372d4d77f774f01a87d104c40ef42d713afbe76195b65f5ca205c5ea7b
2019-12-19 12:29:31 +00:00
drh
c29af653e6 Change an unreachable testcase() into an assert()
FossilOrigin-Name: 062e00c4d7e30155299339eaefe6cbe01953894baebf0af6d7ab3295b7436eb7
2019-12-18 21:22:40 +00:00
drh
396afe6f6a Continue to back away from the LEFT JOIN optimization of check-in [41c27bc0ff1d3135]
by disallowing query flattening if the outer query is DISTINCT.  Without this fix,
if an index scan is run on the table within the view on the right-hand side of the
LEFT JOIN, stale result registers might be accessed yielding incorrect results,
and/or an OP_IfNullRow opcode might be invoked on the un-opened table, resulting
in a NULL-pointer dereference.  This problem was found by the Yongheng and Rui fuzzer.

FossilOrigin-Name: 862974312edf00e9d1068115d1a39b7235b7db68b6d86b81d38a12f025a4748e
2019-12-18 20:51:58 +00:00
drh
6e1c45ef2e Add the --vdbe-debug option to fuzzcheck.
FossilOrigin-Name: 289158aa24b066c453d2bce4bc2dead1c56fb0b23c3f7c4810b34b13627cef34
2019-12-18 13:42:04 +00:00
drh
a7648f02e0 Enhancements to fuzzcheck on unix so that it captures signals and prints
the current test file and test number prior to terminating.

FossilOrigin-Name: ae7cbb246bff3717c283869ccf27ce83611422f3801176819465a8d96f6481bf
2019-12-18 13:02:18 +00:00
drh
8c72afaf33 Add a test case for fix in check-in [1ca0bd982ab1183b]
FossilOrigin-Name: 519864da8bb671941a64bf333c2086ad9a068b5f85759e7abd368f0706d3aefd
2019-12-18 09:17:55 +00:00
drh
94649b6159 Correctly unwind the savepoint stack if the database goes read-only in
the middle of a savepoint.

FossilOrigin-Name: a96d02b4ab8c70cc20b322e4fa3a4b8814f05c51f5d8b071ec9d69e7379f3ea5
2019-12-18 02:12:04 +00:00
drh
50efa58600 Remove an assert() in the code generator that can fail due to an invalid
INSERT statement.  The same assert() appears again in the VDBE and will fire
there if the problem persists in an SQL statement that does not contain
errors.  Gramfuzz find.

FossilOrigin-Name: 9bdd57cb9ad8ac1f4a0f1a3942d94ca5193109eeb1975343c4f0c7abf7135946
2019-12-18 01:31:21 +00:00
drh
75e95e1fcd When processing constant integer values in ORDER BY clauses of window
definitions (see check-in [7e4809eadfe99ebf]) be sure to fully disable
the constant value to avoid an invalid pointer dereference if the expression
is ever duplicated. This fixes a crash report from Yongheng and Rui.

FossilOrigin-Name: 1ca0bd982ab1183bbafce0d260e4dceda5eb766ed2e7793374a88d1ae0bdd2ca
2019-12-18 00:05:50 +00:00
drh
646975c521 Clean up the ExprList that holds the names of columns in a CTE before checking
for unused references in the ALTER TABLE implementation.

FossilOrigin-Name: 8223e79f987feda5c8e51ec52cec6798cca16d070b10558939e2888ca1a25b8e
2019-12-17 12:03:30 +00:00
drh
4dad7ed532 When a table is part of a LEFT JOIN and should be a completely NULL row due to
the semantics of a LEFT JOIN, make sure any generated columns on that row
evaluate to NULL.  Ticket [3b84b42943644d6f]

FossilOrigin-Name: 0271491438ad2a985aeff355173a8d0f1e5813954c82147bc68cb26cca5804c8
2019-12-16 16:52:22 +00:00
drh
d35bdd6c09 Ensure that all ON CONFLICT REPLACE indexes are sorted to the end of the list
of indexes for a table, even for weird cases where the same UNIQUE constraint
occurs twice with the ON CONFLICT REPLACE clause only on the second one.  This
avoids an out-of-order contraint processing problem that can arise due
to the optimization of check-in [469a62ca33081854].

FossilOrigin-Name: 1e3918ca2f2c1cfcfa44249b1d7b847d52cbb8d302a8d4a335c090cfdf22d7a1
2019-12-15 02:49:32 +00:00
drh
95866af326 Abort the OP_Savepoint opcode early if a virtual table xSync method fails,
perhaps due to an interrupt.

FossilOrigin-Name: 672e749aef7351de3c69b365c1f80c756fda4e261b5d2ac1faa01d3a7d5a4c49
2019-12-15 00:36:33 +00:00
drh
7e3f135c62 When a generated column expression is initially parsed, if it contains errors
convert the expression to a simple NULL.  This prevents additional pieces of
the expression tree that are allocated from lookaside from leaking into the
schema, where lookaside allocations are not allowed.

FossilOrigin-Name: a89b38605661e36d192df1d074383b704b34a959fcbc169837c0d4f6848f3208
2019-12-14 19:55:31 +00:00
drh
75f1076885 Due to the previous change, the p5 parameter to OP_VColumn no longer ever
contains extraneous bits, so change a testcase() into an assert() to show
as much.

FossilOrigin-Name: 5b4a88cd3b3a32b1242e0eb733cc0bc4becb830a887b8e6604a4c7452050e163
2019-12-14 18:08:22 +00:00
drh
99670abb82 Do not set OP_Column flags on the instructions generated by
sqlite3ExprCodeGetColumn() if the opcode generated is not really an
OP_Column, which might happen if the column is virtual.
Fix for ticket [b439bfcfb7deedc6]

FossilOrigin-Name: 2401e04730a156aa48787b91af4e516406cb7635145e430be62fd16481816237
2019-12-14 17:43:37 +00:00
drh
aac30f9b50 Make the sqlite3ExprCodeTarget() expression code generator routine robust
in the face of unknown opcodes - it simply generates a NULL value.

FossilOrigin-Name: f8e876c82a246ceed32b166f64e05dfe5ce4ab4c6820be60404109b43d36bb80
2019-12-14 15:01:55 +00:00
dan
5be1b20aec Fix problems in fts3 with processing corrupt records and undefined integer overflows.
FossilOrigin-Name: 3b873029ef1903f76442445343af3786cd59ee66b0e5e0e6b76a0b6b1b5eb88a
2019-12-14 14:15:21 +00:00
drh
e3a4f2cf77 Fix an utterly harmless "applying zero offset to null pointer" UB warning
in sqlite3AtoF():

FossilOrigin-Name: 052fdf5e58b41ccadaa5aac293ceb4d309ced661d46f3a52be9eb8d01d347a82
2019-12-13 23:38:57 +00:00
drh
0f1fa5de04 Patch to the page cache to avoid harmless pointer arithmetic that due to bugs
in the STD-C spec is technically UB.  This is to fix a harmless UBSAN
complaint that OSSFuzz is hitting.

FossilOrigin-Name: c29fc21288e37f81a1617c5e2961c575d3bca6a1d1b013b2e0a99774afb1dcdb
2019-12-13 21:24:46 +00:00
drh
2e2c8819f1 Ensure that there is a containing SELECT statement when processing a
normal aggregate function as if it were a window function.

FossilOrigin-Name: c1014e80b26131200a115beb86929a8f0ded2dd65b075e47373346c0f170576a
2019-12-13 11:42:56 +00:00
drh
0d98598507 *Remove* the macros, not just comment them out.
FossilOrigin-Name: e5dc2939d3e8694d648fc9b73b1174da5b1349e20fbb9cf1c91268939f308f89
2019-12-13 11:32:28 +00:00
drh
4ec4dd701f Remove unused macros formerly used to define built-in aggregate functions.
FossilOrigin-Name: 3ef0d44edd0354cda9b6237f992cb67a2170ee8f1f464b1f38ac36e3a133bc71
2019-12-13 11:31:47 +00:00
drh
77318a3c3f Factor out the conditional (which is only true for rare errors) from the
notValid() function in resolve.c, for a performance improvement and size
reduction.  Also cause failures to set the Expr node to a NULL operator so
that it does not cause problems later in case PRAGMA writable_schema=ON has
been set.  Test cases in TH3.

FossilOrigin-Name: c6af9f655b73200ecc0c4189698e421af6ca584babdc76e73a36d468b2eea1f9
2019-12-12 15:19:18 +00:00
drh
3ecc05bc3f Fix goofy string formatting in lemon.c that dates from the K&R-C days.
FossilOrigin-Name: 48ba5e5a2227257cebafacbb09e9dd91d9b89ab2d52a8b4e4113c1d017d95f41
2019-12-12 00:20:40 +00:00
drh
ce678c297b Improved tracing output from the LEMON-generated parser.
FossilOrigin-Name: 4d6d2fc046d586a1e5989bbb2757f13d0371fbfad0acf45a0e2fd77dffd8d8f9
2019-12-11 18:53:51 +00:00
drh
d4dae75f79 Strengthen check-in [83da4d4104ee1870] by ignoring *all* WHERE-clause
constraints for a virtual table that is the right table of a LEFT JOIN, 
as such constraints are never useful.
This fixes an issue discovered by Manuel Rigger.

FossilOrigin-Name: 840de36df1aaeb4bad9a7c18e97cc560ba3b8c629c4520a05bc456d67b3347b9
2019-12-11 16:22:53 +00:00
drh
a1ca00edd5 When trying to drop a virtual table that has no xDestroy method, invoke
the xDisconnect method rather than doing nothing, to avoid a memory leak.

FossilOrigin-Name: 1fa29a5f2a89b6a1ee067f9cb86de1b66455126349efe3502599fc7ad224170c
2019-12-11 15:07:09 +00:00
drh
31046a9f1f The xDestroy method of a module might be NULL if the schema is corrupt.
FossilOrigin-Name: 0457e7d1961ab1f63e31d9028a9064a895f5c3fcfb56ba25e4f37e90197e3a9f
2019-12-11 14:25:11 +00:00
drh
e94006eb42 Enhance LEMON to provide the ability to mark a rules as one that will never
reduce due to intervention of actions.  Use this new capability to designate
the EXPLAIN rule as NEVER-REDUCES.

FossilOrigin-Name: 136cdefb2f7b582ff1771ac7f9e733dc24c357605526cbfb1834937697c8a922
2019-12-10 20:41:48 +00:00
drh
8e8c88964c Use a statement journal on a CREATE VIRTUAL TABLE statement in case the
VCreate opcode fails.

FossilOrigin-Name: aa3b0eb8c3438ddd3b660bc6bce4b1f4a0e3b5ec897079445231ee1b61210d6a
2019-12-10 18:10:12 +00:00
drh
c075c505f3 Fix parser bugs: require a semicolon after an EXPLAIN command.
FossilOrigin-Name: 707a058a22bd00ef14431cee0d02048cf1be745c0ef5254eda76c325435738ff
2019-12-10 15:05:09 +00:00
dan
db5ed35609 Avoid a buffer overread in fts5 that could occur when parsing corrupt configuration records.
FossilOrigin-Name: 355afd77df21a2265871ca6d075f26b1fa121c7c2682cf512281944ff0c2186d
2019-12-10 03:40:11 +00:00
drh
b5f6243f6d Set the affinity of regular columns prior to computing the values of
generated columns.  Ticket [d7c3f125c925c522]

FossilOrigin-Name: d47d66e3d360d8aa6203a855228d2bc40d9a00d69c15f5066b7632d8fb1ed2cc
2019-12-10 02:48:41 +00:00
drh
0a8764ad7a Rename a local variable to avoid masking a function parameter and thus
causing a harmless compiler warning.

FossilOrigin-Name: f065cf003bd2a3a580cb5b9fa2eacd8be075fe8c2bbc5688e9a9406abbfb3804
2019-12-09 19:44:45 +00:00
drh
2bc5cf9ae9 Add a NEVER() to the ALTER TABLE fix in check-in [1d2e53a39b87e364]
FossilOrigin-Name: c7309ed3c7588c7e51e09418bf5cfd4611539b44c39cef9ed4ae0e385bae7625
2019-12-09 19:29:10 +00:00
drh
0824d5b9a5 The previous check-in was not quite correct, and introduced a new problem
with the USING clause.  Use this version instead.

FossilOrigin-Name: ed28aaa4851202111a502f883ca06359d89b25bba4055c29d7bce2b501cfcc68
2019-12-09 18:22:17 +00:00
drh
926f796e8f Ensure that the SrcList_item.colUsed field is set correctly (set to have a
1 for all columns of the table) when a generated column appears in the USING
clause of a join.

FossilOrigin-Name: 1923efb283e8840fa7436eb20b9d2174ef7cace1690d3b97b572a0db2048b8e3
2019-12-09 17:14:48 +00:00
drh
ebd70eedd5 Fix the NOT NULL verification logic in PRAGMA integrity_check so that it
works for generated columns whose value is the result of a comparison operator.
Ticket [bd8c280671ba44a7]

FossilOrigin-Name: f3b39c71b88cb6721f443de56cdce4c08252453a5e340b00a2bd88dc10c42400
2019-12-09 15:52:07 +00:00