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

Fix a bug in sqlite3_mprintf() which could have caused a buffer

overrun if malloc() failed. (CVS 3998)

FossilOrigin-Name: 5af49a57d4866be21c0206f34584bcc63adc1315
This commit is contained in:
drh
2007-05-15 02:34:09 +00:00
parent f764e6fc3d
commit eaad32b1df
3 changed files with 13 additions and 10 deletions

View File

@@ -729,19 +729,22 @@ static void mout(void *arg, const char *zNewText, int nNewChar){
if( pM->xRealloc==0 ){
nNewChar = pM->nAlloc - pM->nChar - 1;
}else{
pM->nAlloc = pM->nChar + nNewChar*2 + 1;
int nAlloc = pM->nChar + nNewChar*2 + 1;
if( pM->zText==pM->zBase ){
pM->zText = pM->xRealloc(0, pM->nAlloc);
pM->zText = pM->xRealloc(0, nAlloc);
if( pM->zText && pM->nChar ){
memcpy(pM->zText, pM->zBase, pM->nChar);
}
}else{
char *zNew;
zNew = pM->xRealloc(pM->zText, pM->nAlloc);
zNew = pM->xRealloc(pM->zText, nAlloc);
if( zNew ){
pM->zText = zNew;
}else{
return;
}
}
pM->nAlloc = nAlloc;
}
}
if( pM->zText ){