Skip to content

Commit a3f0729

Browse files
Verify in2 is not null before attempting to compute hmac
1 parent 5fa49b4 commit a3f0729

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/crypto_cc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ static const char* sqlcipher_cc_get_provider_version(void *ctx) {
6666

6767
static int sqlcipher_cc_hmac(void *ctx, unsigned char *hmac_key, int key_sz, unsigned char *in, int in_sz, unsigned char *in2, int in2_sz, unsigned char *out) {
6868
CCHmacContext hmac_context;
69+
if(in == NULL) return SQLITE_ERROR;
6970
CCHmacInit(&hmac_context, kCCHmacAlgSHA1, hmac_key, key_sz);
7071
CCHmacUpdate(&hmac_context, in, in_sz);
71-
CCHmacUpdate(&hmac_context, in2, in2_sz);
72+
if(in2 != NULL) CCHmacUpdate(&hmac_context, in2, in2_sz);
7273
CCHmacFinal(&hmac_context, out);
7374
return SQLITE_OK;
7475
}

src/crypto_libtomcrypt.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,10 @@ static int sqlcipher_ltc_hmac(void *ctx, unsigned char *hmac_key, int key_sz, un
145145
unsigned long outlen = key_sz;
146146

147147
hash_idx = find_hash("sha1");
148+
if(in == NULL) return SQLITE_ERROR;
148149
if((rc = hmac_init(&hmac, hash_idx, hmac_key, key_sz)) != CRYPT_OK) return SQLITE_ERROR;
149150
if((rc = hmac_process(&hmac, in, in_sz)) != CRYPT_OK) return SQLITE_ERROR;
150-
if((rc = hmac_process(&hmac, in2, in2_sz)) != CRYPT_OK) return SQLITE_ERROR;
151+
if(in2 != NULL && (rc = hmac_process(&hmac, in2, in2_sz)) != CRYPT_OK) return SQLITE_ERROR;
151152
if((rc = hmac_done(&hmac, out, &outlen)) != CRYPT_OK) return SQLITE_ERROR;
152153
return SQLITE_OK;
153154
}

src/crypto_openssl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,10 @@ static int sqlcipher_openssl_random (void *ctx, void *buffer, int length) {
207207
static int sqlcipher_openssl_hmac(void *ctx, unsigned char *hmac_key, int key_sz, unsigned char *in, int in_sz, unsigned char *in2, int in2_sz, unsigned char *out) {
208208
unsigned int outlen;
209209
HMAC_CTX* hctx = HMAC_CTX_new();
210-
if(hctx == NULL) return SQLITE_ERROR;
210+
if(hctx == NULL || in == NULL) return SQLITE_ERROR;
211211
HMAC_Init_ex(hctx, hmac_key, key_sz, EVP_sha1(), NULL);
212212
HMAC_Update(hctx, in, in_sz);
213-
HMAC_Update(hctx, in2, in2_sz);
213+
if(in2 != NULL) HMAC_Update(hctx, in2, in2_sz);
214214
HMAC_Final(hctx, out, &outlen);
215215
HMAC_CTX_free(hctx);
216216
return SQLITE_OK;

0 commit comments

Comments
 (0)