mirror of
https://github.com/status-im/sqlcipher.git
synced 2025-02-22 16:58:14 +00:00
set the error state from the codec when the plaintext_header_size is invalid
This commit is contained in:
parent
dd2f0b5501
commit
ba14070de1
13
src/crypto.c
13
src/crypto.c
@ -330,8 +330,9 @@ int sqlcipher_codec_pragma(sqlite3* db, int iDb, Parse *pParse, const char *zLef
|
||||
if(ctx) {
|
||||
if( zRight ) {
|
||||
int size = atoi(zRight);
|
||||
if((rc = sqlcipher_codec_ctx_set_plaintext_header_size(ctx, size)) != SQLITE_OK)
|
||||
sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR);
|
||||
/* deliberately ignore result code, if size is invalid it will be set to -1
|
||||
and trip the error later in the codec */
|
||||
sqlcipher_codec_ctx_set_plaintext_header_size(ctx, size);
|
||||
} else {
|
||||
char *size = sqlite3_mprintf("%d", sqlcipher_codec_ctx_get_plaintext_header_size(ctx));
|
||||
codec_vdbe_return_string(pParse, "cipher_plaintext_header_size", size, P4_DYNAMIC);
|
||||
@ -697,6 +698,14 @@ static void* sqlite3Codec(void *iCtx, void *data, Pgno pgno, int mode) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* if the plaintext_header_size is negative that means an invalid size was set via
|
||||
PRAGMA. We can't set the error state on the pager at that point because the pager
|
||||
may not be open yet. However, this is a fatal error state, so abort the codec */
|
||||
if(plaintext_header_sz < 0) {
|
||||
sqlcipher_codec_ctx_set_error(ctx, SQLITE_ERROR);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(pgno == 1) /* adjust starting pointers in data page for header offset on first page*/
|
||||
offset = plaintext_header_sz ? plaintext_header_sz : FILE_HEADER_SZ;
|
||||
|
||||
|
@ -665,6 +665,7 @@ int sqlcipher_codec_ctx_set_plaintext_header_size(codec_ctx *ctx, int size) {
|
||||
ctx->plaintext_header_sz = size;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
ctx->plaintext_header_sz = -1;
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
|
||||
|
@ -183,7 +183,7 @@ do_test test-invalid-plaintext-header-sizes {
|
||||
PRAGMA cipher_plaintext_header_size = 24;
|
||||
CREATE TABLE t1(a,b);
|
||||
"]
|
||||
} {{1 {SQL logic error}} {1 {SQL logic error}} {1 {SQL logic error}}}
|
||||
} {{1 {out of memory}} {1 {out of memory}} {1 {out of memory}}}
|
||||
db close
|
||||
file delete -force test.db
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user