diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..b259d5d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +# This is the EditorConfig (http://editorconfig.org/) coding style file for +# SQLite3 Multiple Ciphers. + +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true + +[makefile.*] +indent_style = tab +indent_size = 8 diff --git a/CHANGELOG.md b/CHANGELOG.md index 137aa5b..564b0e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed issue [#158](../../issues/158)) - add check to verify compatibility of source and target database in backup operation - Fixed issue [#160](../../issues/160)) - fix accessing memory out of array bounds - Fixed issue [#162](../../issues/162)) - fix loading/storing misaligned data +- Fixed issue [#165](../../issues/165)) - fix rekey function by enforcing page size and number of reserved bytes per page - Fixed issue [#166](../../issues/166)) - missing attribute SQLITE_PRIVATE for several internal functions ## [1.8.5] - 2024-05-24 diff --git a/configure.ac b/configure.ac index 66a352e..599cbf5 100644 --- a/configure.ac +++ b/configure.ac @@ -4,7 +4,7 @@ dnl Copyright (C) 2019-2024 Ulrich Telle dnl dnl This file is covered by the same licence as the entire SQLite3 Multiple Ciphers package. -AC_INIT([sqlite3mc], [1.8.5], [ulrich@telle-online.de]) +AC_INIT([sqlite3mc], [1.8.6], [ulrich@telle-online.de]) dnl This is the version tested with, might work with earlier ones. AC_PREREQ([2.69]) diff --git a/readme.md b/readme.md index 5974a83..de63d94 100644 --- a/readme.md +++ b/readme.md @@ -12,6 +12,7 @@ The code was mainly developed under Windows, but was tested under Linux as well. * 1.8.5 - *May 2024* - Based on SQLite version 3.46.0 + - Disable user authentication extension by default For further version information please consult the [CHANGELOG](CHANGELOG.md). diff --git a/src/codecext.c b/src/codecext.c index 0e2c464..b37261c 100644 --- a/src/codecext.c +++ b/src/codecext.c @@ -378,6 +378,7 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey) int nReserved; Pager* pPager; Codec* codec; + int codecAllocated = 0; int rc = SQLITE_ERROR; if (zKey != NULL && nKey < 0) { @@ -425,6 +426,7 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey) /* Database not encrypted, but key specified, therefore encrypt database */ if (codec == NULL) { + codecAllocated = 1; codec = (Codec*) sqlite3_malloc(sizeof(Codec)); rc = (codec != NULL) ? sqlite3mcCodecInit(codec) : SQLITE_NOMEM; } @@ -469,6 +471,11 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey) } else { + sqlite3_mutex_leave(db->mutex); + if (codecAllocated) + { + sqlite3mcCodecFree(codec); + } return rc; } } @@ -578,13 +585,21 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey) /* Set read key equal to write key if necessary */ if (sqlite3mcHasWriteCipher(codec)) { + /* Set Read cipher equal to Write cipher */ sqlite3mcCopyCipher(codec, 0); sqlite3mcSetHasReadCipher(codec, 1); + + /* Enforce page size and number of reserved bytes per page */ + int pageSize = sqlite3mcGetPageSizeWriteCipher(codec); + int reserved = sqlite3mcGetReservedWriteCipher(codec); + mcAdjustBtree(pBt, pageSize, reserved, sqlite3mcGetLegacyWriteCipher(codec)); + sqlite3mcCodecSizeChange(codec, pageSize, reserved); } else { sqlite3mcSetIsEncrypted(codec, 0); } + mcReportCodecError(sqlite3mcGetBtShared(codec), rc); } else {