Skip to content

Commit

Permalink
Remove compile option SQLITE3MC_USE_RANDOM_FILL_MEMORY
Browse files Browse the repository at this point in the history
Using random data to fill unallocated memory just incurs additional overhead without increasing security.
  • Loading branch information
utelle committed Mar 31, 2024
1 parent 26c5c5b commit 80722b0
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 58 deletions.
7 changes: 0 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ OPTION(SQLITE3MC_USE_SQLCIPHER_LEGACY "Use sqlcipher legacy mode as default" OFF

# Additional memory security (filling freed memory allocations with zeros or random data)
OPTION(SQLITE3MC_SECURE_MEMORY "Enable pragma to secure freed memory" OFF)
OPTION(SQLITE3MC_USE_RANDOM_FILL_MEMORY "Fill freed memory with random data" OFF)

# Omit AES hardware support
OPTION(SQLITE3MC_OMIT_AES_HARDWARE_SUPPORT "Omit AES hardware support" OFF)
Expand Down Expand Up @@ -163,12 +162,6 @@ if(SQLITE3MC_SECURE_MEMORY)
SQLITE3MC_SECURE_MEMORY=1
)
endif()
if(SQLITE3MC_USE_RANDOM_FILL_MEMORY)
set(SQLITE3MC_BASE_DEFINITIONS
${SQLITE3MC_BASE_DEFINITIONS}
SQLITE3MC_USE_RANDOM_FILL_MEMORY=1
)
endif()

if(SQLITE3MC_USE_MINIZ OR _SQLITE3MC_REQUIRE_ZLIB)
if(_SQLITE3MC_REQUIRE_ZLIB)
Expand Down
3 changes: 0 additions & 3 deletions build/config.gcc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,4 @@ SQLITE3MC_USE_MINIZ ?= 0
# Set to 1 to enable the PRAGMA
SQLITE3MC_SECURE_MEMORY ?= 0

# Optionally fill freed memory with random data instead of zeros (Default: 0)
#SQLITE3MC_USE_RANDOM_FILL_MEMORY ?= 0

### Configuration dependent settings
3 changes: 0 additions & 3 deletions build/wx_setup.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
<SQLITE_ENABLE_DEBUG>0</SQLITE_ENABLE_DEBUG>
<SQLITE3MC_USE_MINIZ>1</SQLITE3MC_USE_MINIZ>
<SQLITE3MC_SECURE_MEMORY>0</SQLITE3MC_SECURE_MEMORY>
<!--
<SQLITE3MC_USE_RANDOM_FILL_MEMORY>0</SQLITE3MC_USE_RANDOM_FILL_MEMORY>
-->
</PropertyGroup>
<ItemDefinitionGroup>
<Link>
Expand Down
4 changes: 0 additions & 4 deletions premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ project "sqlite3mc_lib"
-- "SQLITE_ENABLE_SQLAR=1"
-- "SQLITE_ENABLE_ZIPFILE=1"
"SQLITE3MC_SECURE_MEMORY=$(SQLITE3MC_SECURE_MEMORY)",
-- "SQLITE3MC_USE_RANDOM_FILL_MEMORY=$(SQLITE3MC_USE_RANDOM_FILL_MEMORY)",
"SQLITE_TEMP_STORE=2",
"SQLITE_USE_URI=1",
"SQLITE_USER_AUTHENTICATION=0",
Expand Down Expand Up @@ -190,7 +189,6 @@ project "sqlite3mc_dll"
-- "SQLITE_ENABLE_SQLAR=1"
-- "SQLITE_ENABLE_ZIPFILE=1"
"SQLITE3MC_SECURE_MEMORY=$(SQLITE3MC_SECURE_MEMORY)",
-- "SQLITE3MC_USE_RANDOM_FILL_MEMORY=$(SQLITE3MC_USE_RANDOM_FILL_MEMORY)",
"SQLITE_TEMP_STORE=2",
"SQLITE_USE_URI=1",
"SQLITE_USER_AUTHENTICATION=0"
Expand Down Expand Up @@ -342,7 +340,6 @@ project "sqlite3mc_libicu"
-- "SQLITE_ENABLE_SQLAR=1"
-- "SQLITE_ENABLE_ZIPFILE=1"
"SQLITE3MC_SECURE_MEMORY=$(SQLITE3MC_SECURE_MEMORY)",
-- "SQLITE3MC_USE_RANDOM_FILL_MEMORY=$(SQLITE3MC_USE_RANDOM_FILL_MEMORY)",
"SQLITE_TEMP_STORE=2",
"SQLITE_USE_URI=1",
"SQLITE_USER_AUTHENTICATION=0",
Expand Down Expand Up @@ -453,7 +450,6 @@ project "sqlite3mc_dllicu"
-- "SQLITE_ENABLE_SQLAR=1"
-- "SQLITE_ENABLE_ZIPFILE=1"
"SQLITE3MC_SECURE_MEMORY=$(SQLITE3MC_SECURE_MEMORY)",
-- "SQLITE3MC_USE_RANDOM_FILL_MEMORY=$(SQLITE3MC_USE_RANDOM_FILL_MEMORY)",
"SQLITE_TEMP_STORE=2",
"SQLITE_USE_URI=1",
"SQLITE_USER_AUTHENTICATION=0"
Expand Down
37 changes: 0 additions & 37 deletions src/memory_secure.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,38 +44,6 @@ static volatile int mcSecureMemoryFlag = 0;
/* Map of default memory allocation methods */
static volatile sqlite3_mem_methods mcDefaultMemoryMethods;

#if SQLITE3MC_ENABLE_RANDOM_FILL_MEMORY

/*
** Fill a buffer with pseudo-random bytes. This is used to preset
** the content of a new memory allocation to unpredictable values and
** to clear the content of a freed allocation to unpredictable values.
*/
static void mcRandomFill(char* pBuf, int nByte)
{
unsigned int x, y, r;
x = SQLITE_PTR_TO_INT(pBuf);
y = nByte | 1;
while( nByte >= 4 )
{
x = (x>>1) ^ (-(int)(x&1) & 0xd0000001);
y = y*1103515245 + 12345;
r = x ^ y;
*(int*)pBuf = r;
pBuf += 4;
nByte -= 4;
}
while( nByte-- > 0 )
{
x = (x>>1) ^ (-(int)(x&1) & 0xd0000001);
y = y*1103515245 + 12345;
r = x ^ y;
*(pBuf++) = r & 0xff;
}
}

#endif

/*
** Return the size of an allocation
*/
Expand All @@ -99,13 +67,8 @@ static void mcMemoryFree(void* pPrior)
{
if (mcSecureMemoryFlag)
{
#if SQLITE3MC_USE_RANDOM_FILL_MEMORY
int nSize = mcMemorySize(pPrior);
mcRandomFill((char*) pPrior, nSize)
#else
int nSize = mcMemorySize(pPrior);
sqlite3mcSecureZeroMemory(pPrior, 0, nSize);
#endif
}
mcDefaultMemoryMethods.xFree(pPrior);
}
Expand Down
4 changes: 0 additions & 4 deletions src/sqlite3mc.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,6 @@ sqlite3mcVersion(sqlite3_context* context, int argc, sqlite3_value** argv)
SQLITE_PRIVATE void sqlite3mcSetMemorySecurity(int value);
SQLITE_PRIVATE int sqlite3mcGetMemorySecurity();

#ifndef SQLITE3MC_USE_RANDOM_FILL_MEMORY
#define SQLITE3MC_USE_RANDOM_FILL_MEMORY 0
#endif

/* Memory locking is currently not supported */
#ifdef SQLITE3MC_ENABLE_MEMLOCK
#undef SQLITE3MC_ENABLE_MEMLOCK
Expand Down

0 comments on commit 80722b0

Please sign in to comment.