]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Disallow writing to, creating or dropping virtual tables from within xSync() callback...
authordanielk1977 <danielk1977@noemail.net>
Wed, 26 Jul 2006 16:22:14 +0000 (16:22 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Wed, 26 Jul 2006 16:22:14 +0000 (16:22 +0000)
FossilOrigin-Name: e705d232324c71738b8b25713a134617dd1fc525

manifest
manifest.uuid
src/build.c
src/vtab.c
test/vtab7.test

index 7310ff1d4b8d7383adcd0673a816191bea48cc1b..224c0a388e329819dff68b7c185e0f8e7901738d 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\san\soverzealous\sassert()\sin\sthe\sUTF-16\sto\sUTF-8\sconverter.\s(CVS\s3338)
-D 2006-07-26T14:57:30
+C Disallow\swriting\sto,\screating\sor\sdropping\svirtual\stables\sfrom\swithin\sxSync()\scallbacks.\s(CVS\s3339)
+D 2006-07-26T16:22:15
 F Makefile.in 9c2a76055c305868cc5f5b73e29a252ff3632c0a
 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -36,7 +36,7 @@ F src/attach.c b11eb4d5d3fb99a10a626956bccc7215f6b68b16
 F src/auth.c 902f4722661c796b97f007d9606bd7529c02597f
 F src/btree.c fc077741b35efd2015b0f56e62d00370bed1fcc8
 F src/btree.h 061c50e37de7f50b58528e352d400cf33ead7418
-F src/build.c b5eb033a663798af85735392bea73f9bd3b16e8a
+F src/build.c 2ea8ad0e2e49b3957692588182524e6c390ab5a9
 F src/callback.c fd9bb39f7ff6b52bad8365617abc61c720640429
 F src/complete.c 7d1a44be8f37de125fcafd3d3a018690b3799675
 F src/date.c cd2bd5d1ebc6fa12d6312f69789ae5b0a2766f2e
@@ -104,7 +104,7 @@ F src/vdbeapi.c a2274726d16893337c60937235040fc36792cb48
 F src/vdbeaux.c f3d25be011aa5b883166466ed06c7c40dbc6cc2e
 F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5
 F src/vdbemem.c 5f0afe3b92bb2c037f8d5d697f7c151fa50783a3
-F src/vtab.c 1fe25b3e59f92ed1f29b63ac9c6f954eb6907a29
+F src/vtab.c cae036dc7b0b7d7f5f17eef646b1d53940a21572
 F src/where.c 75a89957fcb8c068bec55caa4e9d2ed5fa0b0724
 F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
@@ -300,7 +300,7 @@ F test/vtab3.test f38d6d7d19f08bffdadce4d5b8cba078f8118587
 F test/vtab4.test 4b4293341443839ef6dc02f8d9e614702a6c67ff
 F test/vtab5.test 9fb8f335651afe8f870011e2f68e5b00c5ad03cd
 F test/vtab6.test ec0036f29f8a803da9935206f2d9d1b6a8026392
-F test/vtab7.test b87ed57f6f635728c86fbad556e7844927dbc9a8
+F test/vtab7.test 5f9ef9fb84733e928d5d0267c821072561b198d5
 F test/vtab_err.test 11b90203ad60d63746d0de547b1ca014704d8f0e
 F test/where.test ee7c9a6659b07e1ee61177f6e7ff71565ee2c9df
 F test/where2.test a16476a5913e75cf65b38f2daa6157a6b7791394
@@ -377,7 +377,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P 93878e6ebf703be022f83fd670c1aaaf7d4f1266
-R 167e4d31c3ceea093995728310ddba84
-U drh
-Z b21afc244e8797d2644f042e2547a6b5
+P 096bd8212fa06c7271fc24280133d1f0864ffb42
+R 3362c9632601e96a747bcf16cc5e9841
+U danielk1977
+Z 7bc02f9ce0fbfffc39f7d31467d5ba55
index c502d00cd50179c4805be37e8d0359fe6f207d7b..6c0fa1b0713eb10a2f4d6eaaa3a85724c3237ec7 100644 (file)
@@ -1 +1 @@
-096bd8212fa06c7271fc24280133d1f0864ffb42
\ No newline at end of file
+e705d232324c71738b8b25713a134617dd1fc525
\ No newline at end of file
index 66bead5cfd1c23769078ab312418859ab5f3ddc5..b379225aa15f554baaec6aadd9ffe6a022d20bce 100644 (file)
@@ -22,7 +22,7 @@
 **     COMMIT
 **     ROLLBACK
 **
-** $Id: build.c,v 1.408 2006/07/11 14:17:52 drh Exp $
+** $Id: build.c,v 1.409 2006/07/26 16:22:15 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -847,6 +847,12 @@ void sqlite3StartTable(
     int fileFormat;
     sqlite3BeginWriteOperation(pParse, 0, iDb);
 
+#ifndef SQLITE_OMIT_VIRTUALTABLE
+    if( isVirtual ){
+      sqlite3VdbeAddOp(v, OP_VBegin, 0, 0);
+    }
+#endif
+
     /* If the file format and encoding in the database have not been set, 
     ** set them now.
     */
@@ -1954,6 +1960,15 @@ void sqlite3DropTable(Parse *pParse, SrcList *pName, int isView, int noErr){
     Db *pDb = &db->aDb[iDb];
     sqlite3BeginWriteOperation(pParse, 0, iDb);
 
+#ifndef SQLITE_OMIT_VIRTUALTABLE
+    if( IsVirtual(pTab) ){
+      Vdbe *v = sqlite3GetVdbe(pParse);
+      if( v ){
+        sqlite3VdbeAddOp(v, OP_VBegin, 0, 0);
+      }
+    }
+#endif
+
     /* Drop all triggers associated with the table being dropped. Code
     ** is generated to remove entries from sqlite_master and/or
     ** sqlite_temp_master if required.
index 5aa17f6066fa3c82cf86f9c29f725aa0db456f44..2bb157166419e8382aa84367e890e1c8d1a9ddbd 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** This file contains code used to help implement virtual tables.
 **
-** $Id: vtab.c,v 1.28 2006/07/25 15:14:53 danielk1977 Exp $
+** $Id: vtab.c,v 1.29 2006/07/26 16:22:15 danielk1977 Exp $
 */
 #ifndef SQLITE_OMIT_VIRTUALTABLE
 #include "sqliteInt.h"
@@ -394,7 +394,7 @@ int sqlite3VtabCallCreate(sqlite3 *db, int iDb, const char *zTab, char **pzErr){
   }
 
   if( rc==SQLITE_OK && pTab->pVtab ){
-    rc = addToVTrans(db, pTab->pVtab);
+      rc = addToVTrans(db, pTab->pVtab);
   }
 
   return rc;
@@ -512,17 +512,22 @@ int sqlite3VtabSync(sqlite3 *db, int rc2){
   int i;
   int rc = SQLITE_OK;
   int rcsafety;
+  sqlite3_vtab **aVTrans = db->aVTrans;
   if( rc2!=SQLITE_OK ) return rc2;
+
   rc = sqlite3SafetyOff(db);
-  for(i=0; rc==SQLITE_OK && i<db->nVTrans && db->aVTrans[i]; i++){
-    sqlite3_vtab *pVtab = db->aVTrans[i];
+  db->aVTrans = 0;
+  for(i=0; rc==SQLITE_OK && i<db->nVTrans && aVTrans[i]; i++){
+    sqlite3_vtab *pVtab = aVTrans[i];
     int (*x)(sqlite3_vtab *);
     x = pVtab->pModule->xSync;
     if( x ){
       rc = x(pVtab);
     }
   }
+  db->aVTrans = aVTrans;
   rcsafety = sqlite3SafetyOn(db);
+
   if( rc==SQLITE_OK ){
     rc = rcsafety;
   }
@@ -557,10 +562,25 @@ int sqlite3VtabCommit(sqlite3 *db){
 */
 int sqlite3VtabBegin(sqlite3 *db, sqlite3_vtab *pVtab){
   int rc = SQLITE_OK;
-  const sqlite3_module *pModule = pVtab->pModule;
+  const sqlite3_module *pModule;
+
+  /* Special case: If db->aVTrans is NULL and db->nVTrans is greater
+  ** than zero, then this function is being called from within a
+  ** virtual module xSync() callback. It is illegal to write to 
+  ** virtual module tables in this case, so return SQLITE_LOCKED.
+  */
+  if( 0==db->aVTrans && db->nVTrans>0 ){
+    return SQLITE_LOCKED;
+  }
+  if( !pVtab ){
+    return SQLITE_OK;
+  } 
+  pModule = pVtab->pModule;
+
   if( pModule->xBegin ){
     int i;
 
+
     /* If pVtab is already in the aVTrans array, return early */
     for(i=0; (i<db->nVTrans) && 0!=db->aVTrans[i]; i++){
       if( db->aVTrans[i]==pVtab ){
index bb21627e9d6c749b7a61ad3964c22e6f94a29914..5aeb66cd16db50558ff6458ccdca84d0e2258b16 100644 (file)
@@ -12,7 +12,7 @@
 # of this test is reading and writing to the database from within a
 # virtual table xSync() callback.
 #
-# $Id: vtab7.test,v 1.1 2006/07/25 15:14:53 danielk1977 Exp $
+# $Id: vtab7.test,v 1.2 2006/07/26 16:22:16 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -155,6 +155,42 @@ do_test vtab7-3.1 {
 #   }
 # } {1 {library routine called out of sequence}}
 
+# These tests, vtab7-4.*, test that an SQLITE_LOCKED error is returned
+# if an attempt to write to a virtual module table or create a new 
+# virtual table from within an xSync() callback.
+do_test vtab7-4.1 {
+  execsql {
+    CREATE TABLE def(d, e, f);
+    CREATE VIRTUAL TABLE def2 USING echo(def);
+  }
+  set ::callbacks(xSync,abc) {
+    set ::error [catchsql { INSERT INTO def2 VALUES(1, 2, 3) }]
+  }
+  execsql {
+    INSERT INTO abc2 VALUES(1, 2, 3);
+  }
+  set ::error
+} {1 {database table is locked}}
+do_test vtab7-4.2 {
+  set ::callbacks(xSync,abc) {
+    set ::error [catchsql { CREATE VIRTUAL TABLE def3 USING echo(def) }]
+  }
+  execsql {
+    INSERT INTO abc2 VALUES(1, 2, 3);
+  }
+  set ::error
+} {1 {database table is locked}}
+
+do_test vtab7-4.3 {
+  set ::callbacks(xSync,abc) {
+    set ::error [catchsql { DROP TABLE def2 }]
+  }
+  execsql {
+    INSERT INTO abc2 VALUES(1, 2, 3);
+    SELECT name FROM sqlite_master ORDER BY name;
+  }
+  set ::error
+} {1 {database table is locked}}
 
 trace remove variable ::echo_module write echo_module_trace
 unset -nocomplain ::callbacks