Skip to content

Commit

Permalink
Use a uintptr_t field at the start of the allocation to store the siz…
Browse files Browse the repository at this point in the history
…e rather

than a hardcoded 8 bytes. For CHERI, using 8 bytes means that the payload
becomes unaligned.
  • Loading branch information
Khilan Gudka authored and Khilan Gudka committed Jan 11, 2019
1 parent 769749d commit 02b0fa5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/mem1.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ static void *sqlite3MemMalloc(int nByte){
sqlite3_int64 *p;
assert( nByte>0 );
testcase( ROUND8(nByte)!=nByte );
p = SQLITE_MALLOC( nByte+8 );
p = SQLITE_MALLOC( nByte+sizeof(uintptr_t) );
if( p ){
p += (sizeof(uintptr_t)/sizeof(int64_t))-1;
p[0] = nByte;
p++;
}else{
Expand All @@ -165,7 +166,7 @@ static void sqlite3MemFree(void *pPrior){
#else
sqlite3_int64 *p = (sqlite3_int64*)pPrior;
assert( pPrior!=0 );
p--;
p -= (sizeof(uintptr_t)/sizeof(int64_t));
SQLITE_FREE(p);
#endif
}
Expand Down Expand Up @@ -211,9 +212,10 @@ static void *sqlite3MemRealloc(void *pPrior, int nByte){
sqlite3_int64 *p = (sqlite3_int64*)pPrior;
assert( pPrior!=0 && nByte>0 );
assert( nByte==ROUND8(nByte) ); /* EV: R-46199-30249 */
p--;
p = SQLITE_REALLOC(p, nByte+8 );
p -= (sizeof(uintptr_t)/sizeof(int64_t));
p = SQLITE_REALLOC(p, nByte+sizeof(uintptr_t) );
if( p ){
p += (sizeof(uintptr_t)/sizeof(int64_t))-1;
p[0] = nByte;
p++;
}else{
Expand Down

0 comments on commit 02b0fa5

Please sign in to comment.