aboutsummaryrefslogtreecommitdiff
path: root/src/os_unix.c
diff options
context:
space:
mode:
authordan <dan@noemail.net>2017-08-07 18:13:28 +0000
committerdan <dan@noemail.net>2017-08-07 18:13:28 +0000
commit43c1e622cd0b99c2445711aaf6dd0dc149aa5bb5 (patch)
treebcd63a7eca5ffa1c33dae5a6281f714ec523fd0c /src/os_unix.c
parent54640de1566ebaece16c7edc16f5132dc223e8f1 (diff)
downloadsqlite-43c1e622cd0b99c2445711aaf6dd0dc149aa5bb5.tar.gz
sqlite-43c1e622cd0b99c2445711aaf6dd0dc149aa5bb5.zip
Avoid casting a value larger than 2^31 to a (size_t) on systems where it
is a 32-bit type. FossilOrigin-Name: 46c3085dcad6372ac20eff499e17fe11680fdf4adb9186bf8b12221a5047e485
Diffstat (limited to 'src/os_unix.c')
-rw-r--r--src/os_unix.c7
1 files changed, 7 insertions, 0 deletions
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;