From 5f55b10ef651b724fdbfc6c898670df42d40372d Mon Sep 17 00:00:00 2001 From: drh <> Date: Sun, 14 Mar 2021 01:40:08 +0000 Subject: [PATCH] Never allow a double-quoted identifier that appears by itself in the argument list of an index to be interpreted as a string literal. Proposed fix for ticket [1c24a659e6d7f3a1]. FossilOrigin-Name: 7c8aa3812599d58a4c40027c7bcd751f9f03048cdb5a55f1905eea121f38a03d --- manifest | 21 ++++++++++++--------- manifest.uuid | 2 +- src/build.c | 14 ++++++++++++-- src/resolve.c | 2 +- test/quote.test | 12 ++++++++++-- 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index ea6ec02745..2f896d9810 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sgenerated\sautoconf/Makefile.msc\sto\sreflect\sits\ssource. -D 2021-03-12T23:15:08.537 +C Never\sallow\sa\sdouble-quoted\sidentifier\sthat\sappears\sby\sitself\nin\sthe\sargument\slist\sof\san\sindex\sto\sbe\sinterpreted\sas\sa\sstring\sliteral.\nProposed\sfix\sfor\sticket\s[1c24a659e6d7f3a1]. +D 2021-03-14T01:40:08.060 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -486,7 +486,7 @@ F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6 F src/btree.c bafa3a2e8b6622a3aa8791f90c8ecc70e8ae551ba9023f865213890f5b8a8994 F src/btree.h 096cc53baa58be22b02c896d1cf933c38cfc6d65f9253c1367ece8cc88a24de5 F src/btreeInt.h 7614cae30f95b6aed0c7cac7718276a55cfe2c77058cbfd8bef5b75329757331 -F src/build.c fec73c39d756f31d35ccbaa80fe1e040a8d675a318d4d30f41c444167bf3b860 +F src/build.c 29f208c5c423977d8a802a267f913efe5c70a13a6ea9a1894dd3a2764c0419fd F src/callback.c d0b853dd413255d2e337b34545e54d888ea02f20da5ad0e63585b389624c4a6c F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 2a322b9a3d75771fb4d99e0702851f4f68dda982507a0f798eefb0712969a410 @@ -540,7 +540,7 @@ F src/pragma.h 8dc78ab7e9ec6ce3ded8332810a2066f1ef6267e2e03cd7356ee00276125c6cf F src/prepare.c e21b54489b5c73b06ada15e6fc79b5c6f64b06701924a6ca98944ae59e06256f F src/printf.c 2b03a80d7c11bb422115dca175a18bf430e9c9dbaa0eee63b758f0c022f8f34f F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 -F src/resolve.c d95db73d3e6a5c689e5f6604b4d2521350e45f2a0f0f84f5a2dc2bfee56580a0 +F src/resolve.c 1b17a8d29a702d9e5071067306ed621684502728a5a56530bd6df04cec4d3a30 F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92 F src/select.c fc904a7aa7ebfd5c7a57a0141d829c9f5388ac7773e0d1d9668768c1bbc87fc3 F src/shell.c.in 35adf1212d759069b00e468a9304a05a67710c8f8f50e7312335e23cac985d8c @@ -1282,7 +1282,7 @@ F test/quick.test 1681febc928d686362d50057c642f77a02c62e57 F test/quota-glob.test 32901e9eed6705d68ca3faee2a06b73b57cb3c26 F test/quota.test bfb269ce81ea52f593f9648316cd5013d766dd2a F test/quota2.test 7dc12e08b11cbc4c16c9ba2aa2e040ea8d8ab4b8 -F test/quote.test 3f9238ab0e1db70dea89af9afa5859dbd759b0ce0a63da67d547553e2c316475 +F test/quote.test 38b4e3da5daf299868e2a43d9d0a02146c972ea5b13b1f88bf3786a5f698ac7f F test/randexpr1.tcl 40dec52119ed3a2b8b2a773bce24b63a3a746459 F test/randexpr1.test eda062a97e60f9c38ae8d806b03b0ddf23d796df F test/rbu.test 168573d353cd0fd10196b87b0caa322c144ef736 @@ -1910,7 +1910,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P acd63062eb06748bfe9e4886639e4f2b54ea6a496a83f10716abbaba4115500b -R 17f134cb27374fc63f087829be8f2d98 -U larrybr -Z f38b52cd66603df216d7879edb7bd2e5 +P d9f8f488ff9d47fe7bb8838e683bae4fea038f7278ef885ecf292143a0dd88ed +R 2862dbf2bfd7dc2e9fb853368c7badbe +T *branch * tkt-1c24a659 +T *sym-tkt-1c24a659 * +T -sym-trunk * +U drh +Z 3a98b5fcccf805b010dc96d4afb1d5bb diff --git a/manifest.uuid b/manifest.uuid index 214626662f..67faa164e1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d9f8f488ff9d47fe7bb8838e683bae4fea038f7278ef885ecf292143a0dd88ed \ No newline at end of file +7c8aa3812599d58a4c40027c7bcd751f9f03048cdb5a55f1905eea121f38a03d \ No newline at end of file diff --git a/src/build.c b/src/build.c index d60cb72677..097be112d4 100644 --- a/src/build.c +++ b/src/build.c @@ -1604,14 +1604,24 @@ void sqlite3AddDefaultValue( ** accept it. This routine does the necessary conversion. It converts ** the expression given in its argument from a TK_STRING into a TK_ID ** if the expression is just a TK_STRING with an optional COLLATE clause. -** If the expression is anything other than TK_STRING, the expression is -** unchanged. +** +** If the expression is already a TK_ID, clear the EP_DblQuoted flag (if +** that flag exists) to prevent this expression from being converted into +** a string literal by the double-quoted-string-literal hack in +** lookupName, tag-20210313-001. Ticket 1c24a659e6d7f3a1. +** +** If the expression is anything other than TK_STRING or TK_ID, the +** expression is unchanged. */ static void sqlite3StringToId(Expr *p){ if( p->op==TK_STRING ){ p->op = TK_ID; }else if( p->op==TK_COLLATE && p->pLeft->op==TK_STRING ){ p->pLeft->op = TK_ID; + }else if( p->op==TK_ID ){ + /* Prevent this ID from being converted into a string literal. + ** Ticket 1c24a659e6d7f3a1. */ + ExprClearProperty(p, EP_DblQuoted); } } diff --git a/src/resolve.c b/src/resolve.c index 32914befb2..9785aa0fcd 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -561,7 +561,7 @@ static int lookupName( && areDoubleQuotedStringsEnabled(db, pTopNC) ){ /* If a double-quoted identifier does not match any known column name, - ** then treat it as a string. + ** then treat it as a string. tag-20210313-001 ** ** This hack was added in the early days of SQLite in a misguided attempt ** to be compatible with MySQL 3.x, which used double-quotes for strings. diff --git a/test/quote.test b/test/quote.test index 553e96a0b6..dac010c43d 100644 --- a/test/quote.test +++ b/test/quote.test @@ -110,7 +110,7 @@ do_execsql_test 2.2 { PRAGMA writable_schema = 1; CREATE TABLE xyz(a, b, c CHECK (c!="null") ); CREATE INDEX i2 ON t1(x, y, z||"abc"); - CREATE INDEX i3 ON t1("w"); + CREATE INDEX i3 ON t1("w"||""); CREATE INDEX i4 ON t1(x) WHERE z="w"; } @@ -135,10 +135,18 @@ do_execsql_test 2.5 { {CREATE TABLE t1(x, y, z)} {CREATE TABLE xyz(a, b, c CHECK (c!="null") )} {CREATE INDEX i2 ON t1(x, y, z||"abc")} - {CREATE INDEX i3 ON t1("w")} + {CREATE INDEX i3 ON t1("w"||"")} {CREATE INDEX i4 ON t1(x) WHERE z="w"} } +# 2021-03-13 +# ticket 1c24a659e6d7f3a1 +reset_db +do_catchsql_test 3.0 { + CREATE TABLE t1(a,b); + CREATE INDEX x1 on t1("b"); + ALTER TABLE t1 DROP COLUMN b; +} {1 {error in index x1 after drop column: no such column: b}} finish_test -- 2.47.2