8000 error out if key_sz is ever 0 due to context corruption · PHPDOTSQL/sqlcipher@f09f9f9 · GitHub
[go: up one dir, main page]

Skip to content

Commit f09f9f9

Browse files
committed
error out if key_sz is ever 0 due to context corruption
1 parent 0330944 commit f09f9f9

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

src/crypto.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@
7979
#endif
8080

8181

82-
/* extensions defined in pragma.c */
83-
82+
/* extensions defined in pager.c */
8483
void sqlite3pager_get_codec(Pager *pPager, void **ctx);
8584
int sqlite3pager_is_mj_pgno(Pager *pPager, Pgno pgno);
8685
sqlite3_file *sqlite3Pager_get_fd(Pager *pPager);
@@ -91,7 +90,8 @@ void sqlite3pager_sqlite3PagerSetCodec(
9190
void (*xCodecFree)(void*),
9291
void *pCodec
9392
);
94-
/* end extensions defined in pragma.c */
93+
void sqlite3pager_sqlite3PagerSetError(Pager *pPager, int error 10000 );
94+
/* end extensions defined in pager.c */
9595

9696
/*
9797
** Simple shared routines for converting hex char strings to binary data

src/crypto_impl.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,9 @@ int sqlcipher_codec_ctx_set_use_hmac(codec_ctx *ctx, int use) {
353353
}
354354

355355
void sqlcipher_codec_ctx_set_error(codec_ctx *ctx, int error) {
356-
ctx->pBt->db->errCode = error;
356+
CODEC_TRACE(("sqlcipher_codec_ctx_set_error: ctx=%p, error=%d\n", ctx, error));
357+
sqlite3pager_sqlite3PagerSetError(ctx->pBt->pBt->pPager, error);
358+
ctx->pBt->pBt->db->errCode = error;
357359
}
358360

359361
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
502504

503505
CODEC_TRACE(("codec_cipher:entered pgno=%d, mode=%d, size=%d\n", pgno, mode, size));
504506

505-
/* just copy raw data from in to out when key size is 0
506-
* i.e. during a rekey of a plaintext database */
507+
/* the key size should never be zero. If it is, error out. */
507508
if(c_ctx->key_sz == 0) {
508-
memcpy(out, in, size);
509-
return SQLITE_OK;
509+
CODEC_TRACE(("codec_cipher: error possible context corruption, key_sz is zero for pgno=%d\n", pgno));
510+
memset(out, 0, page_sz);
511+
return SQLITE_ERROR;
510512
}
511513

512514
if(mode == CIPHER_ENCRYPT) {

src/pager.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6920,6 +6920,9 @@ void sqlite3pager_sqlite3PagerSetCodec(
69206920
sqlite3PagerSetCodec(pPager, xCodec, xCodecSizeChng, xCodecFree, pCodec);
69216921
}
69226922

6923+
void sqlite3pager_sqlite3PagerSetError( Pager *pPager, int error) {
6924+
pPager->errCode = error;
6925+
}
69236926

69246927
#endif
69256928
/* END CRYPTO */

0 commit comments

Comments
 (0)
0