1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-14 00:22:38 +03:00

Add assert statements to os_unix.c to ensure that any mapped region of the database file is not being read or written using the xRead() or xWrite() methods.

FossilOrigin-Name: 765615f9fba7c1765eb741cb98a09a28b464ee55
This commit is contained in:
dan
2013-03-22 08:58:38 +00:00
parent b26e6c14fe
commit 6101d50471
3 changed files with 19 additions and 7 deletions

View File

@@ -1,5 +1,5 @@
C Fix\scases\swhere\sxRead()\swas\sbeing\sused\sto\sread\sfrom\sa\smemory\smapped\spart\sof\sthe\sdatabase\sfile.
D 2013-03-21T20:39:55.225
C Add\sassert\sstatements\sto\sos_unix.c\sto\sensure\sthat\sany\smapped\sregion\sof\sthe\sdatabase\sfile\sis\snot\sbeing\sread\sor\swritten\susing\sthe\sxRead()\sor\sxWrite()\smethods.
D 2013-03-22T08:58:38.319
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 9a804abbd3cae82d196e4d33aba13239e32522a5
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -160,7 +160,7 @@ F src/notify.c 976dd0f6171d4588e89e874fcc765e92914b6d30
F src/os.c 87ea1cd1259c5840848e34007d72e772a2ab7528
F src/os.h 8d92f87f5fe14b060a853ca704b8ef6d3daee79b
F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04
F src/os_unix.c be66c31337361a72227638d6f41c7f2031739642
F src/os_unix.c 18153e6fc03580e95d28fb39d47a4e8b64b36187
F src/os_win.c f7da4dc0a2545c0a430080380809946ae4d676d6
F src/pager.c 520001015155efee9599c807dfd38e5fff9c6e36
F src/pager.h 241d72dc0905df042da165f086d03505cb0bb50c
@@ -1039,7 +1039,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
P c8eac290a7240d69494bd0dad5ed1fdc2505f703
R 0cdb7517bc23cd336050741c62097e56
P 5c9e9df27b9f2c46cd55388a858d4e78ee564975
R eb2eb83f96de836951dbdb14158ccee8
U dan
Z 0dd43854f08b06a022f11b1a174cdf13
Z 42c0bd3cd106c51e7465866daa07e0a3

View File

@@ -1 +1 @@
5c9e9df27b9f2c46cd55388a858d4e78ee564975
765615f9fba7c1765eb741cb98a09a28b464ee55

View File

@@ -249,6 +249,8 @@ struct unixFile {
unsigned char transCntrChng; /* True if the transaction counter changed */
unsigned char dbUpdate; /* True if any part of database file changed */
unsigned char inNormalWrite; /* True if in a normal write operation */
sqlite3_int64 mmapSize; /* Size of xMremap() */
void *pMapRegion; /* Area memory mapped */
#endif
#ifdef SQLITE_TEST
/* In test mode, increase the size of this structure a bit so that
@@ -3072,6 +3074,7 @@ static int unixRead(
unixFile *pFile = (unixFile *)id;
int got;
assert( id );
assert( offset>=pFile->mmapSize ); /* Never read from the mmapped region */
/* If this is a database file (not a journal, master-journal or temp
** file), the bytes in the locking range should never be read or written. */
@@ -3154,6 +3157,7 @@ static int unixWrite(
int wrote = 0;
assert( id );
assert( amt>0 );
assert( offset>=pFile->mmapSize ); /* Never write into the mmapped region */
/* If this is a database file (not a journal, master-journal or temp
** file), the bytes in the locking range should never be read or written. */
@@ -4457,6 +4461,8 @@ static int unixMremap(
i64 nOldRnd; /* nOld rounded up */
assert( iOff==0 );
assert( p->mmapSize==nOld );
assert( p->pMapRegion==0 || p->pMapRegion==(*ppMap) );
/* If the SQLITE_MREMAP_EXTEND flag is set, then the size of the requested
** mapping (nNew bytes) may be greater than the size of the database file.
@@ -4494,6 +4500,7 @@ static int unixMremap(
/* On OSX or Linux, reuse the old mapping if it is the right size. */
#if defined(__APPLE__) || defined(__linux__)
if( nNewRnd==nOldRnd ){
VVA_ONLY( p->mmapSize = nNew; )
return SQLITE_OK;
}
#endif
@@ -4502,6 +4509,7 @@ static int unixMremap(
if( nOldRnd!=0 ){
void *pOld = *ppMap;
munmap(pOld, nOldRnd);
VVA_ONLY( p->mmapSize = 0; p->pMapRegion = 0; );
}
/* And, if required, use mmap() to create a new mapping. */
@@ -4511,7 +4519,10 @@ static int unixMremap(
pNew = mmap(0, nNewRnd, flags, MAP_SHARED, p->h, iOff);
if( pNew==MAP_FAILED ){
pNew = 0;
VVA_ONLY( p->mmapSize = 0; p->pMapRegion = 0; )
rc = SQLITE_IOERR_MREMAP;
}else{
VVA_ONLY( p->mmapSize = nNew; p->pMapRegion = pNew; )
}
}
@@ -4846,6 +4857,7 @@ static int fillInUnixFile(
pNew->pVfs = pVfs;
pNew->zPath = zFilename;
pNew->ctrlFlags = (u8)ctrlFlags;
VVA_ONLY( pNew->mmapSize = 0; )
if( sqlite3_uri_boolean(((ctrlFlags & UNIXFILE_URI) ? zFilename : 0),
"psow", SQLITE_POWERSAFE_OVERWRITE) ){
pNew->ctrlFlags |= UNIXFILE_PSOW;