From dff5b425622eabda4d3217ad4e7b116c24bbc207 Mon Sep 17 00:00:00 2001 From: Stephen Lombardo Date: Tue, 10 Nov 2020 17:35:19 -0500 Subject: [PATCH] force return NULL pointer on CODEC error --- src/crypto.c | 2 ++ test/sqlcipher-codecerror.text | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/crypto.c b/src/crypto.c index 4e4eeca..31eb0aa 100644 --- a/src/crypto.c +++ b/src/crypto.c @@ -714,6 +714,7 @@ static void* sqlite3Codec(void *iCtx, void *data, Pgno pgno, int mode) { if(rc != SQLITE_OK) { /* clear results of failed cipher operation and set error */ sqlcipher_memset((unsigned char*) buffer+offset, 0, page_sz-offset); sqlcipher_codec_ctx_set_error(ctx, rc); + return NULL; } memcpy(pData, buffer, page_sz); /* copy buffer data back to pData and return */ return pData; @@ -739,6 +740,7 @@ static void* sqlite3Codec(void *iCtx, void *data, Pgno pgno, int mode) { if(rc != SQLITE_OK) { /* clear results of failed cipher operation and set error */ sqlcipher_memset((unsigned char*)buffer+offset, 0, page_sz-offset); sqlcipher_codec_ctx_set_error(ctx, rc); + return NULL; } return buffer; /* return persistent buffer data, pData remains intact */ break; diff --git a/test/sqlcipher-codecerror.text b/test/sqlcipher-codecerror.text index ef1ac8f..ca1fe96 100644 --- a/test/sqlcipher-codecerror.text +++ b/test/sqlcipher-codecerror.text @@ -111,7 +111,7 @@ do_test codec-error-journal-wal { execsql { PRAGMA cipher_fail_next_encrypt = 0; PRAGMA key = 'testkey'; --- PRAGMA integrity_check; + PRAGMA integrity_check; PRAGMA cipher_integrity_check; }