Skip to content

Commit 4f5a821

Browse files
committed
do not attempt to lock the database as it will fail if the first page is invalid
1 parent 83cddfd commit 4f5a821

2 files changed

Lines changed: 1 addition & 30 deletions

File tree

src/crypto_impl.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ static int sqlcipher_check_connection(const char *filename, char *key, int key_s
12561256

12571257
int sqlcipher_codec_ctx_integrity_check(codec_ctx *ctx, Parse *pParse, char *column) {
12581258
Pgno page = 1;
1259-
int i, trans_rc, rc = 0;
1259+
int i, rc = 0;
12601260
char *result;
12611261
unsigned char *hmac_out = NULL;
12621262
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
12841284
goto cleanup;
12851285
}
12861286

1287-
/* establish an exclusive lock on the database */
1288-
if((trans_rc = sqlite3BtreeBeginTrans(ctx->pBt, 2, 0)) != SQLITE_OK) {
1289-
sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, "unable to lock database", P4_TRANSIENT);
1290-
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
1291-
goto cleanup;
1292-
}
1293-
12941287
sqlite3OsFileSize(fd, &file_sz);
12951288
hmac_out = sqlcipher_malloc(ctx->hmac_sz);
12961289

@@ -1330,7 +1323,6 @@ int sqlcipher_codec_ctx_integrity_check(codec_ctx *ctx, Parse *pParse, char *col
13301323
}
13311324

13321325
cleanup:
1333-
if(trans_rc == SQLITE_OK) sqlite3BtreeRollback(ctx->pBt, SQLITE_OK, 0);
13341326
if(hmac_out != NULL) sqlcipher_free(hmac_out, ctx->hmac_sz);
13351327
return SQLITE_OK;
13361328
}

test/sqlcipher-integrity.test

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -308,25 +308,4 @@ do_test integrity-check-plaintext-header {
308308
} {{} 1 {{HMAC verification failed for page 1} {HMAC verification failed for page 2}}}
309309
file delete -force test.db
310310

311-
# verify database locking for cipher_integrity_check
312-
do_test integrity-check-locking {
313-
sqlite_orig db test.db
314-
sqlite_orig db2 test.db
315-
316-
execsql {
317-
PRAGMA key = 'test';
318-
CREATE TABLE t1(a,b);
319-
BEGIN EXCLUSIVE;
320-
INSERT INTO t1(a,b) VALUES (1,2);
321-
}
322-
323-
execsql {
324-
PRAGMA key = 'test';
325-
PRAGMA cipher_integrity_check;
326-
} db2
327-
} {{unable to lock database}}
328-
sqlite_orig db test.db
329-
sqlite_orig db2 test.db
330-
file delete -force test.db
331-
332311
finish_test

0 commit comments

Comments
 (0)