From 43c1e622cd0b99c2445711aaf6dd0dc149aa5bb5 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 7 Aug 2017 18:13:28 +0000 Subject: Avoid casting a value larger than 2^31 to a (size_t) on systems where it is a 32-bit type. FossilOrigin-Name: 46c3085dcad6372ac20eff499e17fe11680fdf4adb9186bf8b12221a5047e485 --- src/os_unix.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/os_unix.c') diff --git a/src/os_unix.c b/src/os_unix.c index 157be3c3a..99a06279f 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -3858,6 +3858,13 @@ static int unixFileControl(sqlite3_file *id, int op, void *pArg){ if( newLimit>sqlite3GlobalConfig.mxMmap ){ newLimit = sqlite3GlobalConfig.mxMmap; } + + /* The value of newLimit may be eventually cast to (size_t) and passed + ** to mmap(). Restrict its value to 2GB if (size_t) is a 32-bit type. */ + if( sizeof(size_t)<8 ){ + newLimit = (newLimit & 0x7FFFFFFF); + } + *(i64*)pArg = pFile->mmapSizeMax; if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){ pFile->mmapSizeMax = newLimit; -- cgit v1.2.3