From: dan Date: Sat, 24 Feb 2018 08:26:21 +0000 (+0000) Subject: Test edge cases in the zonefile module. Fix a broken error message in the same. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=87f1670de82fafa52df8d92e09693099200d1554;p=thirdparty%2Fsqlite.git Test edge cases in the zonefile module. Fix a broken error message in the same. FossilOrigin-Name: 1764ade22b52eba0226ae2e6e837a1b0967023eabd7d50e9f87c5e7042ea2f12 --- diff --git a/ext/zonefile/zonefile.c b/ext/zonefile/zonefile.c index bf0e5df238..844516509a 100644 --- a/ext/zonefile/zonefile.c +++ b/ext/zonefile/zonefile.c @@ -2313,22 +2313,21 @@ static int zonefileGetFile( "SELECT filename FROM %Q.'%q_shadow_file' WHERE fileid=?", pTab->zDb, pTab->zName ); - if( rc!=SQLITE_OK ){ - zonefileTransferError(pCtx); - return SQLITE_ERROR; - } + if( rc==SQLITE_ERROR ) zonefileTransferError(pCtx); } - iFileid = sqlite3_column_int64(pCsr->pSelect,1); - sqlite3_bind_int64(pTab->pIdToName, 1, iFileid); - if( SQLITE_ROW==sqlite3_step(pTab->pIdToName) ){ - *pzFile = (const char*)sqlite3_column_text(pTab->pIdToName, 0); - }else{ - rc = sqlite3_reset(pTab->pIdToName); - if( rc==SQLITE_OK ){ - rc = SQLITE_CORRUPT_VTAB; + if( rc==SQLITE_OK ){ + iFileid = sqlite3_column_int64(pCsr->pSelect,1); + sqlite3_bind_int64(pTab->pIdToName, 1, iFileid); + if( SQLITE_ROW==sqlite3_step(pTab->pIdToName) ){ + *pzFile = (const char*)sqlite3_column_text(pTab->pIdToName, 0); }else{ - zonefileTransferError(pCtx); + rc = sqlite3_reset(pTab->pIdToName); + if( rc==SQLITE_OK ){ + rc = SQLITE_CORRUPT_VTAB; + }else{ + zonefileTransferError(pCtx); + } } } diff --git a/ext/zonefile/zonefile1.test b/ext/zonefile/zonefile1.test index 1f0d7a6e53..92255f1219 100644 --- a/ext/zonefile/zonefile1.test +++ b/ext/zonefile/zonefile1.test @@ -231,12 +231,16 @@ do_execsql_test 3.1 { SELECT quote(dd.v)==quote(cc.v) FROM cc JOIN dd USING (k) } {1 1 1} -do_execsql_test 3.2 { +do_execsql_test 3.2.1 { DELETE FROM cc_files; INSERT INTO cc_files(filename,ekey) VALUES('test.zonefile','abcdefghij'); SELECT quote(dd.v)==quote(cc.v) FROM cc JOIN dd USING (k) } {0 0 0} +do_execsql_test 3.2.2 { + SELECT rowid,sz FROM cc; +} {1000 44 1001 55 1002 66} + do_execsql_test 3.3 { UPDATE cc_files SET ekey = '0123456789'; SELECT quote(dd.v)==quote(cc.v) FROM cc JOIN dd USING (k) @@ -256,6 +260,11 @@ do_execsql_test 3.6 { SELECT ekey FROM cc_files } {{}} +forcedelete test.zonefile +do_catchsql_test 3.7 { + SELECT * FROM cc; +} {1 {failed to open file "test.zonefile" for reading}} + #------------------------------------------------------------------------- # Check that a file that uses an unknown compression method is handled # correctly (an error is returned). @@ -559,15 +568,64 @@ foreach {tn cond} { 6 "k BETWEEN 10 AND 20" 7 "k > 100 AND k < 200" } { - do_execsql_test 11.$tn.1 [subst { + do_execsql_test 11.1.$tn.1 [subst { SELECT count(*) FROM nm WHERE $cond }] [db one "SELECT count(*) FROM data WHERE $cond"] - do_execsql_test 11.$tn.2 [subst { + do_execsql_test 11.1.$tn.2 [subst { SELECT count(*) FROM nm WHERE $cond AND v!=(SELECT v FROM data WHERE k=nm.k); }] 0 } +close [open test1.zonefile w+] +do_catchsql_test 11.2.1 { + SELECT * FROM nm WHERE k=24; +} {1 {SQL logic error}} +forcedelete test1.zonefile +do_catchsql_test 11.2.2 { + SELECT * FROM nm WHERE k=24; +} {1 {failed to open file "test1.zonefile" for reading}} + +do_catchsql_test 11.3.1 { + DELETE FROM nm_shadow_file; + SELECT * FROM nm WHERE k=24; +} {1 {database disk image is malformed}} +do_catchsql_test 11.3.2 { + DROP TABLE nm_shadow_file; + SELECT * FROM nm WHERE k=24; +} {1 {no such table: main.nm_shadow_file}} +db close +sqlite3 db test.db +load_static_extension db zonefile +do_catchsql_test 11.3.3 { + SELECT * FROM nm WHERE k=24; +} {1 {no such table: main.nm_shadow_file}} + +#------------------------------------------------------------------------- +# +reset_db +load_static_extension db zonefile +do_execsql_test 11.0 { + CREATE TABLE data(k INTEGER PRIMARY KEY, frame, idx, v BLOB); + INSERT INTO data VALUES(1, 1, -1, randomblob(200)); + INSERT INTO data VALUES(2, 2, -1, randomblob(200)); + INSERT INTO data VALUES(3, 3, -1, randomblob(200)); + SELECT zonefile_write('test.zonefile', 'data', + '{"encryptionType":"xor","encryptionKey":"pass"}' + ); + + CREATE VIRTUAL TABLE nm USING zonefile(cachesize=2); + INSERT INTO nm_files(filename,ekey) VALUES('test.zonefile','pass'); +} {{}} + +set i 0 +foreach id {1 2 3 2 3 1} { + do_execsql_test 11.1.$i { + SELECT data.v=nm.v FROM data,nm WHERE data.k=$id AND nm.k=$id + } 1 + incr i +} + finish_test diff --git a/ext/zonefile/zonefilefault.test b/ext/zonefile/zonefilefault.test index 30975145bb..acd6373561 100644 --- a/ext/zonefile/zonefilefault.test +++ b/ext/zonefile/zonefilefault.test @@ -46,8 +46,12 @@ set sql { '{"compressionTypeContent":"zstd_global_dict"}' ); } - +set HAVE_ZSTD 0 if {[catch { db eval $sql }]==0} { + set HAVE_ZSTD 1 +} + +if {$HAVE_ZSTD} { do_faultsim_test 1.2 -faults oom* -prep { sqlite3 db test.db load_static_extension db zonefile @@ -82,7 +86,7 @@ do_execsql_test 1.4.0 { INSERT INTO tt VALUES(9, -1, -1, randomblob(100)); CREATE VIRTUAL TABLE ttz USING zonefile; } -if {[catch { db eval $sql }]==0} { +if {$HAVE_ZSTD} { faultsim_save_and_close do_faultsim_test 1.4 -faults oom* -prep { faultsim_restore_and_reopen @@ -151,9 +155,10 @@ do_faultsim_test 2.3 -faults oom* -prep { } #------------------------------------------------------------------------- +# reset_db faultsim_save_and_close -do_faultsim_test 3 -faults oom* -prep { +do_faultsim_test 3.1 -faults oom* -prep { faultsim_restore_and_reopen load_static_extension db zonefile } -body { @@ -162,5 +167,76 @@ do_faultsim_test 3 -faults oom* -prep { faultsim_test_result {0 {}} } +faultsim_save_and_close +do_faultsim_test 3.2 -faults oom* -prep { + faultsim_restore_and_reopen + load_static_extension db zonefile +} -body { + execsql { DROP TABLE t1 } +} -test { + faultsim_test_result {0 {}} +} + +#------------------------------------------------------------------------- +# +reset_db +load_static_extension db zonefile +do_execsql_test 4.0 { + CREATE TABLE zz(k INTEGER PRIMARY KEY, frame INTEGER, idx INTEGER, v BLOB); + INSERT INTO zz VALUES(1, -1, -1, randomblob(100)); + INSERT INTO zz VALUES(2, -1, -1, randomblob(100)); + INSERT INTO zz VALUES(3, -1, -1, randomblob(100)); + SELECT zonefile_write('test.zonefile', 'zz'); + CREATE VIRTUAL TABLE zone USING zonefile; + INSERT INTO zone_files(filename) VALUES('test.zonefile'); +} {{}} + +faultsim_save_and_close +do_faultsim_test 4.1 -faults oom* -prep { + faultsim_restore_and_reopen + load_static_extension db zonefile +} -body { + execsql { SELECT v IS NULL FROM zone WHERE k = 2 } +} -test { + faultsim_test_result {0 0} +} + + +if {$HAVE_ZSTD} { + set params { + {"encryptionType":"xor","encryptionKey":"pass", + "compressionTypeContent":"zstd_global_dict" + } + } +} else { + set params { {"encryptionType":"xor","encryptionKey":"pass" } } +} +do_execsql_test 4.2 { + SELECT zonefile_write('test.zonefile', 'zz', $params); + CREATE VIRTUAL TABLE zone2 USING zonefile; + INSERT INTO zone2_files(filename,ekey) VALUES('test.zonefile','pass'); +} {{}} + +faultsim_save_and_close +do_faultsim_test 4.3 -faults oom* -prep { + faultsim_restore_and_reopen + load_static_extension db zonefile + execsql { UPDATE zone2_files SET ekey='pass' } +} -body { + execsql { SELECT v IS NULL FROM zone2 WHERE k = 2 } +} -test { + faultsim_test_result {0 0} +} + +#------------------------------------------------------------------------- +reset_db +do_faultsim_test 4.3 -faults oom* -prep { + faultsim_restore_and_reopen +} -body { + load_static_extension db zonefile +} -test { + faultsim_test_result {0 {}} {1 {initialization of zonefile failed: }} +} + finish_test diff --git a/manifest b/manifest index 49978784ab..504bfd748d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\swith\shandling\s"k\s>=\s?"\sconstraints\sin\sthe\szonefile\smodule. -D 2018-02-23T21:01:15.048 +C Test\sedge\scases\sin\sthe\szonefile\smodule.\sFix\sa\sbroken\serror\smessage\sin\sthe\ssame. +D 2018-02-24T08:26:21.801 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in a2d2fb8d17c39ab5ec52beb27850b903949080848236923f436156b72a958737 @@ -409,10 +409,10 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04 F ext/userauth/userauth.c 3410be31283abba70255d71fd24734e017a4497f F ext/zonefile/README.md df86ef5b4f9aa8b07e1c8124b3f2dcea616927385aad59d525b784f0a06d446c -F ext/zonefile/zonefile.c 886dc98b402cbfce902327725bcdb7e209e4ac4d41270be312f966023ca77b9b -F ext/zonefile/zonefile1.test f9d80a9138b34953d25387b094b886a3c66ddfb3ce07cd6e11bae20ef0bc5b02 +F ext/zonefile/zonefile.c eeba1f8a353661998b2e54d499c0fd7241946d48285d1e20fc86ac1c81651b6c +F ext/zonefile/zonefile1.test 43e10166a74187d997a224c4f199cabfdbf4c17f704759fd37b0fcb8616c26a3 F ext/zonefile/zonefileenc.test 10e770105edeff6a05df6be8db5481eaa8fcda2422ec5446ad21b34ed70d02d7 -F ext/zonefile/zonefilefault.test 319dc0df65ee9dd89da5c7a9b72b88decfafbe627ab29ca11d93678732cca35e +F ext/zonefile/zonefilefault.test 6f0b10364972981380de65e8665b7a8f882a70ec7ee188695fe199f2851e180e F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60 @@ -1712,7 +1712,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P dbbcbf0066ef82c789981feff78d95861a836e6e23a22ad3bb698dd257062f75 -R a381dedf59b4651a47fa5bb736b93522 +P 9a99afafa3fb9ec4823e5030cb04a685d64942ec04a1154b729dc4c0f313dc4a +R 6618d746fdec54fbaf0229c804a7cf37 U dan -Z e0cceed6c3e6fbf110dfbc3e5d5a0f09 +Z 6cb0aff8f941832f5fc5365c2afb34dd diff --git a/manifest.uuid b/manifest.uuid index 13b89fcfb2..6d2999ac44 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9a99afafa3fb9ec4823e5030cb04a685d64942ec04a1154b729dc4c0f313dc4a \ No newline at end of file +1764ade22b52eba0226ae2e6e837a1b0967023eabd7d50e9f87c5e7042ea2f12 \ No newline at end of file