mirror of
https://github.com/status-im/sqlcipher.git
synced 2025-02-23 17:28:17 +00:00
error out if key_sz is ever 0 due to context corruption
This commit is contained in:
parent
0330944245
commit
f09f9f908a
@ -79,8 +79,7 @@
|
||||
#endif
|
||||
|
||||
|
||||
/* extensions defined in pragma.c */
|
||||
|
||||
/* extensions defined in pager.c */
|
||||
void sqlite3pager_get_codec(Pager *pPager, void **ctx);
|
||||
int sqlite3pager_is_mj_pgno(Pager *pPager, Pgno pgno);
|
||||
sqlite3_file *sqlite3Pager_get_fd(Pager *pPager);
|
||||
@ -91,7 +90,8 @@ void sqlite3pager_sqlite3PagerSetCodec(
|
||||
void (*xCodecFree)(void*),
|
||||
void *pCodec
|
||||
);
|
||||
/* end extensions defined in pragma.c */
|
||||
void sqlite3pager_sqlite3PagerSetError(Pager *pPager, int error);
|
||||
/* end extensions defined in pager.c */
|
||||
|
||||
/*
|
||||
** Simple shared routines for converting hex char strings to binary data
|
||||
|
@ -353,7 +353,9 @@ int sqlcipher_codec_ctx_set_use_hmac(codec_ctx *ctx, int use) {
|
||||
}
|
||||
|
||||
void sqlcipher_codec_ctx_set_error(codec_ctx *ctx, int error) {
|
||||
ctx->pBt->db->errCode = error;
|
||||
CODEC_TRACE(("sqlcipher_codec_ctx_set_error: ctx=%p, error=%d\n", ctx, error));
|
||||
sqlite3pager_sqlite3PagerSetError(ctx->pBt->pBt->pPager, error);
|
||||
ctx->pBt->pBt->db->errCode = error;
|
||||
}
|
||||
|
||||
int sqlcipher_codec_ctx_get_pagesize(codec_ctx *ctx) {
|
||||
@ -502,11 +504,11 @@ int sqlcipher_page_cipher(codec_ctx *ctx, int for_ctx, Pgno pgno, int mode, int
|
||||
|
||||
CODEC_TRACE(("codec_cipher:entered pgno=%d, mode=%d, size=%d\n", pgno, mode, size));
|
||||
|
||||
/* just copy raw data from in to out when key size is 0
|
||||
* i.e. during a rekey of a plaintext database */
|
||||
/* the key size should never be zero. If it is, error out. */
|
||||
if(c_ctx->key_sz == 0) {
|
||||
memcpy(out, in, size);
|
||||
return SQLITE_OK;
|
||||
CODEC_TRACE(("codec_cipher: error possible context corruption, key_sz is zero for pgno=%d\n", pgno));
|
||||
memset(out, 0, page_sz);
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
|
||||
if(mode == CIPHER_ENCRYPT) {
|
||||
|
@ -6920,6 +6920,9 @@ void sqlite3pager_sqlite3PagerSetCodec(
|
||||
sqlite3PagerSetCodec(pPager, xCodec, xCodecSizeChng, xCodecFree, pCodec);
|
||||
}
|
||||
|
||||
void sqlite3pager_sqlite3PagerSetError( Pager *pPager, int error) {
|
||||
pPager->errCode = error;
|
||||
}
|
||||
|
||||
#endif
|
||||
/* END CRYPTO */
|
||||
|
Loading…
x
Reference in New Issue
Block a user