8000 fix regression itroduced in prior commit · magic-coder/sqlcipher@f291262 · GitHub
[go: up one dir, main page]

Skip to content

Commit f291262

Browse files
committed
fix regression itroduced in prior commit
1 parent f25510f commit f291262

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

src/crypto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static void cipher_hex2bin(const char *hex, int sz, unsigned char *out){
152152
static void cipher_bin2hex(const unsigned char* in, int sz, char *out) {
153153
int i;
154154
for(i=0; i < sz; i++) {
155-
sqlite3_snprintf(2, out + (i*2), "%02x ", in[i]);
155+
sqlite3_snprintf(3, out + (i*2), "%02x ", in[i]);
156156
}
157157
}
158158

src/crypto_impl.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,9 @@ static int sqlcipher_cipher_ctx_set_keyspec(cipher_ctx *ctx, const unsigned char
389389

390390
ctx->keyspec[0] = 'x';
391391
ctx->keyspec[1] = '\'';
392-
ctx->keyspec[ctx->keyspec_sz - 1] = '\'';
393392
cipher_bin2hex(key, key_sz, ctx->keyspec + 2);
394393
cipher_bin2hex(salt, salt_sz, ctx->keyspec + (key_sz * 2) + 2);
395-
394+
ctx->keyspec[ctx->keyspec_sz - 1] = '\'';
396395
return SQLITE_OK;
397396
}
398397

@@ -980,15 +979,9 @@ int sqlcipher_codec_ctx_migrate(codec_ctx *ctx) {
980979
memcpy(key, ctx->read_ctx->pass, ctx->read_ctx->pass_sz);
981980

982981
if(db_filename){
983-
982+
const char* commands[4];
984983
char *attach_command = sqlite3_mprintf("ATTACH DATABASE '%s-migrated' as migrate KEY '%s';",
985984
db_filename, key);
986-
const char* commands[] = {
987-
upgrade_4k_format == 1 ? pragma_4k_kdf_iter : "",
988-
upgrade_1x_format == 1 ? pragma_hmac_off : "",
989-
attach_command,
990-
"SELECT sqlcipher_export('migrate');",
991-
};
992985

993986
int rc = sqlcipher_check_connection(db_filename, key, key_sz, "");
994987
if(rc == SQLITE_OK){
@@ -1019,7 +1012,11 @@ int sqlcipher_codec_ctx_migrate(codec_ctx *ctx) {
10191012
goto handle_error;
10201013
}
10211014

1022-
1015+
commands[0] = upgrade_4k_format == 1 ? pragma_4k_kdf_iter : "";
1016+
commands[1] = upgrade_1x_format == 1 ? pragma_hmac_off : "";
1017+
commands[2] = attach_command;
1018+
commands[3] = "SELECT sqlcipher_export('migrate');";
1019+
10231020
for(command_idx = 0; command_idx < (sizeof(commands)/sizeof(commands[0])); command_idx++){
10241021
const char *command = commands[command_idx];
10251022
if(strcmp(command, "") == 0){

0 commit comments

Comments
 (0)
0