]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix a potential division by zero error in this version of RBU that might occur if... branch-3.14
authordan <Dan Kennedy>
Tue, 27 Sep 2022 17:00:48 +0000 (17:00 +0000)
committerdan <Dan Kennedy>
Tue, 27 Sep 2022 17:00:48 +0000 (17:00 +0000)
FossilOrigin-Name: 73edd93adf3f15ad46b07017d1010131fd52f1d16da8d1c73503058b5b1c7cdd

ext/rbu/rbuempty.test [new file with mode: 0644]
ext/rbu/sqlite3rbu.c
manifest
manifest.uuid

diff --git a/ext/rbu/rbuempty.test b/ext/rbu/rbuempty.test
new file mode 100644 (file)
index 0000000..1e56da2
--- /dev/null
@@ -0,0 +1,77 @@
+# 2022 September 27
+#
+# 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.
+#
+#***********************************************************************
+#
+
+source [file join [file dirname [info script]] rbu_common.tcl]
+set ::testprefix rbuempty
+
+db close
+sqlite3_shutdown
+sqlite3_config_uri 1
+
+forcedelete rbu.db
+sqlite3 db test.db
+do_execsql_test 1.0 {
+  CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT);
+  INSERT INTO t1 VALUES(1, 'one');
+  INSERT INTO t1 VALUES(2, 'two');
+  INSERT INTO t1 VALUES(3, 'three');
+
+  ATTACH 'rbu.db' AS aux;
+  CREATE TABLE aux.data_t1(a, b, rbu_control);
+  DETACH aux;
+}
+
+do_test 1.1 {
+  sqlite3rbu rbu test.db rbu.db
+  lappend ::v [rbu state]
+  lappend ::v [rbu bp_progress]
+  while {[rbu step]=="SQLITE_OK"} {
+    lappend ::v [rbu state]
+    lappend ::v [rbu bp_progress]
+  }
+  lappend ::v [rbu state]
+  lappend ::v [rbu bp_progress]
+  rbu close
+} {SQLITE_DONE}
+
+do_execsql_test 1.2 {
+  SELECT * FROM t1
+} {1 one 2 two 3 three}
+
+forcedelete rbu.db
+do_execsql_test 1.3 {
+  ATTACH 'rbu.db' AS aux;
+  CREATE TABLE aux.data_t1(a, b, rbu_control);
+  INSERT INTO aux.data_t1 VALUES(4, 'FOUR', 0);
+  DETACH aux;
+}
+
+do_test 1.4 {
+  while {1} {
+    sqlite3rbu rbu test.db rbu.db
+    lappend ::v [rbu state]
+    lappend ::v [rbu bp_progress]
+    set rc [rbu step]
+    lappend ::v [rbu state]
+    lappend ::v [rbu bp_progress]
+    rbu close
+    if {$rc!="SQLITE_OK"} break
+    db eval { SELECT * FROM t1 } 
+    db eval { PRAGMA wal_checkpoint = restart }
+  }
+} {}
+
+
+
+finish_test
+
+
index 73c6647a2c7b79565cd69b278f1d75049eb93762..03e8463fe751d4424d409b6446c946055ce6f3a2 100644 (file)
@@ -2597,14 +2597,16 @@ static void rbuSetupCheckpoint(sqlite3rbu *p, RbuState *pState){
     if( rc2!=SQLITE_INTERNAL ) p->rc = rc2;
   }
 
-  if( p->rc==SQLITE_OK ){
+  if( p->rc==SQLITE_OK && p->nFrame>0 ){
     p->eStage = RBU_STAGE_CKPT;
     p->nStep = (pState ? pState->nRow : 0);
     p->aBuf = rbuMalloc(p, p->pgsz);
     p->iWalCksum = rbuShmChecksum(p);
   }
 
-  if( p->rc==SQLITE_OK && pState && pState->iWalCksum!=p->iWalCksum ){
+  if( p->rc==SQLITE_OK 
+  && (p->nFrame==0 || (pState && pState->iWalCksum!=p->iWalCksum))
+  ){
     p->rc = SQLITE_DONE;
     p->eStage = RBU_STAGE_DONE;
   }
index 5656b11205d9186b753adc164fa523a1fa844427..dc84fe187dbf7508b52914b05a9f16ff95856094 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Version\s3.14.2
-D 2016-09-12T18:50:49.277
+C Fix\sa\spotential\sdivision\sby\szero\serror\sin\sthis\sversion\sof\sRBU\sthat\smight\soccur\sif\san\sexternal\sclient\scheckpoints\sa\swal\sfile\screated\sby\sa\ssuspended\sRBU\sprocess.
+D 2022-09-27T17:00:48.149
 F Makefile.in cfd8fb987cd7a6af046daa87daa146d5aad0e088
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc 6fef1e10792656c94fe1393092de6c8ba6ea1c88
@@ -245,6 +245,7 @@ F ext/rbu/rbuC.test efe47db508a0269b683cb2a1913a425ffd39a831
 F ext/rbu/rbu_common.tcl a38e8e2d4a50fd6aaf151633714c1b1d2fae3ead
 F ext/rbu/rbucrash.test 8d2ed5d4b05fef6c00c2a6b5f7ead71fa172a695
 F ext/rbu/rbudiff.test b3c7675810b81de98a930a87fcd40d9ae545619d
+F ext/rbu/rbuempty.test 860d59e354ac753094b5e8df24a10ed36eab27632f7651c588f5f1eea3883c29
 F ext/rbu/rbufault.test cc0be8d5d392d98b0c2d6a51be377ea989250a89
 F ext/rbu/rbufault2.test 9a7f19edd6ea35c4c9f807d8a3db0a03a5670c06
 F ext/rbu/rbufault3.test 54a399888ac4af44c68f9f58afbed23149428bca
@@ -253,7 +254,7 @@ F ext/rbu/rbuprogress.test 2023a7df2c523e3df1cb532eff811cda385a789a
 F ext/rbu/rbusave.test 0f43b6686084f426ddd040b878426452fd2c2f48
 F ext/rbu/rbuvacuum.test 4a977447c15c2581ab668781d9ef4294382530e0
 F ext/rbu/rbuvacuum2.test 45009e127c3fb385e5c0fd5a8a63fb922a79d0ab
-F ext/rbu/sqlite3rbu.c 948677ee0ec57da51148e6c5f64ac68afcf36ab2
+F ext/rbu/sqlite3rbu.c b6b6c561ec022f9d5594181fd329b3d5632de954e03f5aa6361426d6c30c08e7
 F ext/rbu/sqlite3rbu.h db8858120c9be14b60c9225f9da28221f5f6b945
 F ext/rbu/test_rbu.c 1a6bbc6982e32485a48df111d0bb1934d537eabd
 F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761
@@ -1509,10 +1510,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P a04a21ad5aa1a56d50388d6cdb88bae754218a0a
-R 073817cadc2d2cf4f1a705c7b7ab3a16
-T +bgcolor * #d0c0ff
-T +sym-release *
-T +sym-version-3.14.2 *
-U drh
-Z 3b9eb30be1058877308d90519a39b4b7
+P 29dbef4b8585f753861a36d6dd102ca634197bd6
+R d5973768d2dd25ebb2c053ba524a3661
+U dan
+Z 179292894a96dbff387572676ab03d5b
+# Remove this line to create a well-formed Fossil manifest.
index 7d599e65114fd5cbd87815ab109ee92c64c2af25..7d2c7910cdfe2d0d41448adc7f036cc19accb1d6 100644 (file)
@@ -1 +1 @@
-29dbef4b8585f753861a36d6dd102ca634197bd6
\ No newline at end of file
+73edd93adf3f15ad46b07017d1010131fd52f1d16da8d1c73503058b5b1c7cdd
\ No newline at end of file