mirror of
				https://github.com/sqlite/sqlite.git
				synced 2025-10-30 07:05:46 +03:00 
			
		
		
		
	In memsys5, initialize new allocations to non-zero bytes. Change the content
of freed allocations to prevent use after free. These changes in SQLITE_DEBUG only. FossilOrigin-Name: ba5f0a5599dece6d8f3dfe652800c28875c74a24
This commit is contained in:
		
							
								
								
									
										13
									
								
								src/mem5.c
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								src/mem5.c
									
									
									
									
									
								
							| @@ -275,6 +275,12 @@ static void *memsys5MallocUnsafe(int nByte){ | ||||
|   if( mem5.maxCount<mem5.currentCount ) mem5.maxCount = mem5.currentCount; | ||||
|   if( mem5.maxOut<mem5.currentOut ) mem5.maxOut = mem5.currentOut; | ||||
|  | ||||
| #ifdef SQLITE_DEBUG | ||||
|   /* Make sure the allocated memory does not assume that it is set to zero | ||||
|   ** or retains a value from a previous allocation */ | ||||
|   memset(&mem5.zPool[i*mem5.szAtom], 0xAA, iFullSz); | ||||
| #endif | ||||
|  | ||||
|   /* Return a pointer to the allocated memory. */ | ||||
|   return (void*)&mem5.zPool[i*mem5.szAtom]; | ||||
| } | ||||
| @@ -332,6 +338,13 @@ static void memsys5FreeUnsafe(void *pOld){ | ||||
|     } | ||||
|     size *= 2; | ||||
|   } | ||||
|  | ||||
| #ifdef SQLITE_DEBUG | ||||
|   /* Overwrite freed memory with the 0x55 bit pattern to verify that it is | ||||
|   ** not used after being freed */ | ||||
|   memset(&mem5.zPool[iBlock*mem5.szAtom], 0x55, size); | ||||
| #endif | ||||
|  | ||||
|   memsys5Link(iBlock, iLogsize); | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user