]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Ensure that an error is reported if an attempt is made to update a wal mode database...
authordan <dan@noemail.net>
Wed, 11 Feb 2015 16:25:27 +0000 (16:25 +0000)
committerdan <dan@noemail.net>
Wed, 11 Feb 2015 16:25:27 +0000 (16:25 +0000)
FossilOrigin-Name: 6fc5d4d26a603b3906f02ceea0f507780d0c35eb

ext/ota/otaA.test [new file with mode: 0644]
ext/ota/sqlite3ota.c
manifest
manifest.uuid

diff --git a/ext/ota/otaA.test b/ext/ota/otaA.test
new file mode 100644 (file)
index 0000000..9ba9606
--- /dev/null
@@ -0,0 +1,82 @@
+# 2014 August 30
+#
+# The author disclaims copyright to this source code.  In place of
+# a legal notice, here is a blessing:
+#
+#    May you do good and not evil.
+#    May you find forgiveness for yourself and forgive others.
+#    May you share freely, never taking more than you give.
+#
+#***********************************************************************
+#
+# This file contains tests for the OTA module. More specifically, it
+# contains tests to ensure that it is an error to attempt to update
+# a wal mode database via OTA.
+#
+
+if {![info exists testdir]} {
+  set testdir [file join [file dirname [info script]] .. .. test]
+}
+source $testdir/tester.tcl
+set ::testprefix otaA
+
+set db_sql {
+  CREATE TABLE t1(a PRIMARY KEY, b, c);
+}
+set ota_sql {
+  CREATE TABLE data_t1(a, b, c, ota_control);
+  INSERT INTO data_t1 VALUES(1, 2, 3, 0);
+  INSERT INTO data_t1 VALUES(4, 5, 6, 0);
+  INSERT INTO data_t1 VALUES(7, 8, 9, 0);
+}
+
+do_test 1.0 {
+  forcedelete test.db ota.db
+
+  sqlite3 db test.db
+  db eval $db_sql
+  db eval { PRAGMA journal_mode = wal }
+  db close
+
+  sqlite3 db ota.db
+  db eval $ota_sql
+  db close
+
+  sqlite3ota ota test.db ota.db
+  ota step
+} {SQLITE_ERROR}
+do_test 1.1 {
+  list [catch { ota close } msg] $msg
+} {1 {SQLITE_ERROR - cannot update wal mode database}}
+
+do_test 2.0 {
+  forcedelete test.db ota.db
+
+  sqlite3 db test.db
+  db eval $db_sql
+  db close
+
+  sqlite3 db ota.db
+  db eval $ota_sql
+  db close
+
+  sqlite3ota ota test.db ota.db
+  ota step
+  ota close
+} {SQLITE_OK}
+
+do_test 2.1 {
+  sqlite3 db test.db
+  db eval {PRAGMA journal_mode = wal}
+  db close
+  sqlite3ota ota test.db ota.db
+  ota step
+} {SQLITE_ERROR}
+
+do_test 2.2 {
+  list [catch { ota close } msg] $msg
+} {1 {SQLITE_ERROR - cannot update wal mode database}}
+
+
+finish_test
+
index 39f2042b96ab05868fca88446fdaa9a1e0a4a963..5a97a9a57c2cacde39d15b03d8c0538a770d413a 100644 (file)
@@ -188,8 +188,10 @@ struct ota_file {
   sqlite3_file *pReal;            /* Underlying file handle */
   ota_vfs *pOtaVfs;               /* Pointer to the ota_vfs object */
   sqlite3ota *pOta;               /* Pointer to ota object (ota target only) */
+
   int openFlags;                  /* Flags this file was opened with */
   unsigned int iCookie;           /* Cookie value for main db files */
+  unsigned char iWriteVer;        /* "write-version" value for main db files */
 
   int nShm;                       /* Number of entries in apShm[] array */
   char **apShm;                   /* Array of mmap'd *-shm regions */
@@ -2056,6 +2058,11 @@ sqlite3ota *sqlite3ota_open(const char *zTarget, const char *zOta){
       p->rc = sqlite3_exec(p->db, OTA_CREATE_STATE, 0, 0, &p->zErrmsg);
     }
 
+    if( p->rc==SQLITE_OK && p->pTargetFd->iWriteVer>1 ){
+      p->rc = SQLITE_ERROR;
+      p->zErrmsg = sqlite3_mprintf("cannot update wal mode database");
+    }
+
     if( p->rc==SQLITE_OK ){
       pState = otaLoadState(p);
       assert( pState || p->rc!=SQLITE_OK );
@@ -2264,7 +2271,11 @@ static int otaVfsRead(
   ota_file *p = (ota_file*)pFile;
   int rc = p->pReal->pMethods->xRead(p->pReal, zBuf, iAmt, iOfst);
   if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
-    p->iCookie = otaGetU32((unsigned char*)&zBuf[24]);
+    /* These look like magic numbers. But they are stable, as they are part
+    ** of the definition of the SQLite file format, which may not change. */
+    unsigned char *pBuf = (unsigned char*)zBuf;
+    p->iCookie = otaGetU32(&pBuf[24]);
+    p->iWriteVer = pBuf[19];
   }
   return rc;
 }
@@ -2281,7 +2292,11 @@ static int otaVfsWrite(
   ota_file *p = (ota_file*)pFile;
   int rc = p->pReal->pMethods->xWrite(p->pReal, zBuf, iAmt, iOfst);
   if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
-    p->iCookie = otaGetU32((unsigned char*)&zBuf[24]);
+    /* These look like magic numbers. But they are stable, as they are part
+    ** of the definition of the SQLite file format, which may not change. */
+    unsigned char *pBuf = (unsigned char*)zBuf;
+    p->iCookie = otaGetU32(&pBuf[24]);
+    p->iWriteVer = pBuf[19];
   }
   return rc;
 }
index 24b4a814d127f1779179dec77d3e9bca4b73615a..5f28a04b522df8357079bd3a5b8143ba69aec962 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Further\stweaks\sto\swork\swith\szipvfs.
-D 2015-02-10T20:00:38.125
+C Ensure\sthat\san\serror\sis\sreported\sif\san\sattempt\sis\smade\sto\supdate\sa\swal\smode\sdatabase\svia\sota.
+D 2015-02-11T16:25:27.816
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -133,8 +133,9 @@ F ext/ota/ota6.test 1fbba5fd46e3e0bfa5ae1d0caf9da27d15cb7cdf
 F ext/ota/ota7.test 1fe2c5761705374530e29f70c39693076028221a
 F ext/ota/ota8.test cd70e63a0c29c45c0906692827deafa34638feda
 F ext/ota/ota9.test d3eee95dd836824d07a22e5efcdb7bf6e869358b
+F ext/ota/otaA.test 95566a8d193113867b960eadf85b310937f2fe03
 F ext/ota/otafault.test 508ba87c83d632670ac0f94371a465d4bb4d49dd
-F ext/ota/sqlite3ota.c 1f96966839c57e6a6f4ca8e8a771b23fbf79b8f6
+F ext/ota/sqlite3ota.c 7400075206e6cb8cbb32fc7268cb2fcf6321ea66
 F ext/ota/sqlite3ota.h 1cc7201086fe65a36957740381485a24738c4077
 F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761
 F ext/rtree/rtree.c 14e6239434d4e3f65d3e90320713f26aa24e167f
@@ -1253,7 +1254,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P e729668168f00325459bc2e9b515aa95e57f2754
-R 245c10d0f1613c672374bc7bdeb81ab9
+P 0f152416be792457c52417aeb531ac860d12a5bd
+R d9bfc5d0f25bbcabd7abf7a0a51ab0ed
 U dan
-Z 8b6e26dd39381b8c315cf4c234f64cec
+Z 85c9979bf4d433f3d16c5b8b0ec7a03f
index 5c028557bbf093203ea1df512c75bc72de359dd8..d68e5af259e14acfa19fdaa5fc1d735bcb5cdfa3 100644 (file)
@@ -1 +1 @@
-0f152416be792457c52417aeb531ac860d12a5bd
\ No newline at end of file
+6fc5d4d26a603b3906f02ceea0f507780d0c35eb
\ No newline at end of file