diff options
author | shane <shane@noemail.net> | 2009-02-05 03:00:06 +0000 |
---|---|---|
committer | shane <shane@noemail.net> | 2009-02-05 03:00:06 +0000 |
commit | d20010c70ec8ddf0629cf9b3b5f99b47ec1007e3 (patch) | |
tree | bc65d59173fcb5fad63603241eeb42f9ccf65e4b /src/mem2.c | |
parent | dc2c491525ef28f3edd4798f0b51324e7b667ad8 (diff) | |
download | sqlite-d20010c70ec8ddf0629cf9b3b5f99b47ec1007e3.tar.gz sqlite-d20010c70ec8ddf0629cf9b3b5f99b47ec1007e3.zip |
Improved overrun detection in mem2.c (SQLITE_MEMDEBUG). Previously was only checking up to 3 extra bytes allocated due to rounding. (CVS 6261)
FossilOrigin-Name: a6fe3d6b02734b23fe067a373c0232024a782a6c
Diffstat (limited to 'src/mem2.c')
-rw-r--r-- | src/mem2.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/mem2.c b/src/mem2.c index 25a6a56de..156237fcc 100644 --- a/src/mem2.c +++ b/src/mem2.c @@ -19,7 +19,7 @@ ** This file contains implementations of the low-level memory allocation ** routines specified in the sqlite3_mem_methods object. ** -** $Id: mem2.c,v 1.42 2008/12/10 19:26:24 drh Exp $ +** $Id: mem2.c,v 1.43 2009/02/05 03:00:06 shane Exp $ */ #include "sqliteInt.h" @@ -163,9 +163,11 @@ static struct MemBlockHdr *sqlite3MemsysGetHeader(void *pAllocation){ pInt = (int*)pAllocation; pU8 = (u8*)pAllocation; assert( pInt[nReserve/sizeof(int)]==(int)REARGUARD ); - assert( (nReserve-0)<=p->iSize || pU8[nReserve-1]==0x65 ); - assert( (nReserve-1)<=p->iSize || pU8[nReserve-2]==0x65 ); - assert( (nReserve-2)<=p->iSize || pU8[nReserve-3]==0x65 ); + /* This checks any of the "extra" bytes allocated due + ** to rounding up to an 8 byte boundary to ensure + ** they haven't been overwritten. + */ + while( nReserve-- > p->iSize ) assert( pU8[nReserve]==0x65 ); return p; } @@ -186,6 +188,7 @@ static int sqlite3MemSize(void *p){ */ static int sqlite3MemInit(void *NotUsed){ UNUSED_PARAMETER(NotUsed); + assert( (sizeof(struct MemBlockHdr)&7) == 0 ); if( !sqlite3GlobalConfig.bMemstat ){ /* If memory status is enabled, then the malloc.c wrapper will already ** hold the STATIC_MEM mutex when the routines here are invoked. */ |