1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-12 13:01:09 +03:00

When available, use posix_fallocate() rather than ftruncate() to allocate

space for mmap()ed -shm files, since posix_fallocate() gives an error if
no disk space is available whereas ftruncate() is silent and leaves the system
vulnerable to a SIGBUS upon first write to the mmap()ed region.
Ticket [5eaa61ea1881040b17449ca043b6f8fd9ca55dc3]

FossilOrigin-Name: 356259617cfad04492a02912fdf781f54a2b4494
This commit is contained in:
drh
2012-11-13 10:54:12 +00:00
parent b43081675d
commit 0fbb50ee15
4 changed files with 20 additions and 10 deletions

View File

@@ -4168,11 +4168,19 @@ static int unixShmMap(
** the requested memory region.
*/
if( !bExtend ) goto shmpage_out;
#if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
if( osFallocate(pShmNode->h, sStat.st_size, nByte)!=0 ){
rc = unixLogError(SQLITE_IOERR_SHMSIZE, "fallocate",
pShmNode->zFilename);
goto shmpage_out;
}
#else
if( robust_ftruncate(pShmNode->h, nByte) ){
rc = unixLogError(SQLITE_IOERR_SHMSIZE, "ftruncate",
pShmNode->zFilename);
goto shmpage_out;
}
#endif
}
}