do not attempt to lock the database as it will fail if the first page is invalid

This commit is contained in:
Stephen Lombardo 2019-05-28 15:40:59 -04:00
parent 83cddfda21
commit 4f5a821e93
2 changed files with 1 additions and 30 deletions

View File

@ -1256,7 +1256,7 @@ cleanup:
int sqlcipher_codec_ctx_integrity_check(codec_ctx *ctx, Parse *pParse, char *column) {
Pgno page = 1;
int i, trans_rc, rc = 0;
int i, rc = 0;
char *result;
unsigned char *hmac_out = NULL;
sqlite3_file *fd = sqlite3PagerFile(ctx->pBt->pBt->pPager);
@ -1284,13 +1284,6 @@ int sqlcipher_codec_ctx_integrity_check(codec_ctx *ctx, Parse *pParse, char *col
goto cleanup;
}
/* establish an exclusive lock on the database */
if((trans_rc = sqlite3BtreeBeginTrans(ctx->pBt, 2, 0)) != SQLITE_OK) {
sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, "unable to lock database", P4_TRANSIENT);
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
goto cleanup;
}
sqlite3OsFileSize(fd, &file_sz);
hmac_out = sqlcipher_malloc(ctx->hmac_sz);
@ -1330,7 +1323,6 @@ int sqlcipher_codec_ctx_integrity_check(codec_ctx *ctx, Parse *pParse, char *col
}
cleanup:
if(trans_rc == SQLITE_OK) sqlite3BtreeRollback(ctx->pBt, SQLITE_OK, 0);
if(hmac_out != NULL) sqlcipher_free(hmac_out, ctx->hmac_sz);
return SQLITE_OK;
}

View File

@ -308,25 +308,4 @@ do_test integrity-check-plaintext-header {
} {{} 1 {{HMAC verification failed for page 1} {HMAC verification failed for page 2}}}
file delete -force test.db
# verify database locking for cipher_integrity_check
do_test integrity-check-locking {
sqlite_orig db test.db
sqlite_orig db2 test.db
execsql {
PRAGMA key = 'test';
CREATE TABLE t1(a,b);
BEGIN EXCLUSIVE;
INSERT INTO t1(a,b) VALUES (1,2);
}
execsql {
PRAGMA key = 'test';
PRAGMA cipher_integrity_check;
} db2
} {{unable to lock database}}
sqlite_orig db test.db
sqlite_orig db2 test.db
file delete -force test.db
finish_test