From c10960834f0caf049c9b48236204c4dff961c940 Mon Sep 17 00:00:00 2001 From: Stephen Lombardo Date: Thu, 25 Feb 2010 11:58:56 -0500 Subject: [PATCH] fix issue where it wasn't possible to ATTACH an unencrypted database --- src/crypto.c | 3 +-- test/crypto.test | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/src/crypto.c b/src/crypto.c index 7945293..7c339cc 100644 --- a/src/crypto.c +++ b/src/crypto.c @@ -460,9 +460,8 @@ int sqlite3CodecAttach(sqlite3* db, int nDb, const void *zKey, int nKey) { cipher_ctx_copy(ctx->write_ctx, ctx->read_ctx); sqlite3BtreeSetPageSize(ctx->pBt, sqlite3BtreeGetPageSize(ctx->pBt), EVP_MAX_IV_LENGTH, 0); - return SQLITE_OK; } - return SQLITE_ERROR; + return SQLITE_OK; } void sqlite3FreeCodecArg(void *pCodecArg) { diff --git a/test/crypto.test b/test/crypto.test index 16c5e0e..aea8755 100644 --- a/test/crypto.test +++ b/test/crypto.test @@ -477,4 +477,73 @@ db2 close file delete -force test.db file delete -force test2.db +# create an encrypted database, attach an unencrypted volume +# copy data between, verify the unencypted database is good afterwards +do_test encryped-attach-unencrypted { + sqlite_orig db test.db + + execsql { + CREATE TABLE t1(a,b); + } + + sqlite_orig db2 test2.db + execsql { + PRAGMA key='testkey'; + CREATE TABLE t1(a,b); + BEGIN; + } db2 + + for {set i 1} {$i<=1000} {incr i} { + set r [expr {int(rand()*500000)}] + execsql "INSERT INTO t1 VALUES($i,$r);" db2 + } + + execsql { + COMMIT; + ATTACH DATABASE 'test.db' AS test KEY ''; + INSERT INTO test.t1 SELECT * FROM t1; + DETACH DATABASE test; + } db2 + + execsql { + SELECT count(*) FROM t1; + } +} {1000} +db close +db2 close +file delete -force test.db +file delete -force test2.db + +# create an unencrypted database, attach an unencrypted volume +# copy data between, verify the unencypted database is good afterwards +do_test unencryped-attach-unencrypted { + sqlite_orig db test.db + + execsql { + CREATE TABLE t1(a,b); + } + + sqlite_orig db2 test2.db + execsql { + CREATE TABLE t1(a,b); + BEGIN; + } db2 + + for {set i 1} {$i<=1000} {incr i} { + set r [expr {int(rand()*500000)}] + execsql "INSERT INTO t1 VALUES($i,$r);" db2 + } + + execsql { + COMMIT; + ATTACH DATABASE 'test.db' AS test; + INSERT INTO test.t1 SELECT * FROM t1; + DETACH DATABASE test; + } db2 + + execsql { + SELECT count(*) FROM t1; + } +} {1000} + finish_test