8000 Merge branch 'Sc00bz-patch-1' into prerelease · g-coder/sqlcipher@4c87a22 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4c87a22

Browse files
Merge branch 'Sc00bz-patch-1' into prerelease
2 parents 4216a5f + a5d41bf commit 4c87a22

File tree

2 files changed

+15
-2
lines changed
< 8000 div class="d-flex flex-items-center flex-justify-between gap-2 pt-3 pt-lg-4 pb-2 position-sticky top-0 color-bg-default" style="z-index:2">

2 files changed

+15
-2
lines changed

src/crypto.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,19 @@ static void cipher_bin2hex(const unsigned char* in, int sz, char *out) {
160160
}
161161
}
162162

163+
static int cipher_isHex(const unsigned char *hex, int sz){
164+
int i;
165+
for(i = 0; i < sz; i++) {
166+
unsigned char c = hex[i];
167+
if ((c < '0' || c > '9') &&
168+
(c < 'A' || c > 'F') &&
169+
(c < 'a' || c > 'f')) {
170+
return 0;
171+
}
172+
}
173+
return 1;
174+
}
175+
163176
/* extensions defined in crypto_impl.c */
164177
typedef struct codec_ctx codec_ctx;
165178

src/crypto_impl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -885,12 +885,12 @@ static int sqlcipher_cipher_ctx_key_derive(codec_ctx *ctx, cipher_ctx *c_ctx) {
885885
if(ctx->read_ctx->provider->random(ctx->read_ctx->provider_ctx, ctx->kdf_salt, FILE_HEADER_SZ) != SQLITE_OK) return SQLITE_ERROR;
886886
ctx->need_kdf_salt = 0;
887887
}
888-
if (c_ctx->pass_sz == ((c_ctx->key_sz * 2) + 3) && sqlite3StrNICmp((const char *)c_ctx->pass ,"x'", 2) == 0) {
888+
if (c_ctx->pass_sz == ((c_ctx->key_sz * 2) + 3) && sqlite3StrNICmp((const char *)c_ctx->pass ,"x'", 2) == 0 && cipher_isHex(c_ctx->pass + 2, c_ctx->key_sz * 2)) {
889889
int n = c_ctx->pass_sz - 3; /* adjust for leading x' and tailing ' */
890890
const unsigned char *z = c_ctx->pass + 2; /* adjust lead offset of x' */
891891
CODEC_TRACE(("cipher_ctx_key_derive: using raw key from hex\n"));
892892
cipher_hex2bin(z, n, c_ctx->key);
893-
} else if (c_ctx->pass_sz == (((c_ctx->key_sz + ctx->kdf_salt_sz) * 2) + 3) && sqlite3StrNICmp((const char *)c_ctx->pass ,"x'", 2) == 0) {
893+
} else if (c_ctx->pass_sz == (((c_ctx->key_sz + ctx->kdf_salt_sz) * 2) + 3) && sqlite3StrNICmp((const char *)c_ctx->pass ,"x'", 2) == 0 && cipher_isHex(c_ctx->pass + 2, (c_ctx->key_sz + ctx->kdf_salt_sz) * 2)) {
894894
const unsigned char *z = c_ctx->pass + 2; /* adjust lead offset of x' */
895895
CODEC_TRACE(("cipher_ctx_key_derive: using raw key from hex\n"));
896896
cipher_hex2bin(z, (c_ctx->key_sz * 2), c_ctx->key);

0 commit comments

Comments
 (0)
0