Skip to content

Commit 5214d1f

Browse files
committed
Fix a couple of memory-sanitizer complaints that could be triggered by a corrupt database.
2 parents f711021 + 2099d80 commit 5214d1f

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/btree.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7637,7 +7637,9 @@ static int balance_nonroot(
76377637
}
76387638
pgno = get4byte(pRight);
76397639
while( 1 ){
7640-
rc = getAndInitPage(pBt, pgno, &apOld[i], 0, 0);
7640+
if( rc==SQLITE_OK ){
7641+
rc = getAndInitPage(pBt, pgno, &apOld[i], 0, 0);
7642+
}
76417643
if( rc ){
76427644
memset(apOld, 0, (i+1)*sizeof(MemPage*));
76437645
goto balance_cleanup;
@@ -7676,12 +7678,10 @@ static int balance_nonroot(
76767678
if( pBt->btsFlags & BTS_FAST_SECURE ){
76777679
int iOff;
76787680

7681+
/* If the following if() condition is not true, the db is corrupted.
7682+
** The call to dropCell() below will detect this. */
76797683
iOff = SQLITE_PTR_TO_INT(apDiv[i]) - SQLITE_PTR_TO_INT(pParent->aData);
7680-
if( (iOff+szNew[i])>(int)pBt->usableSize ){
7681-
rc = SQLITE_CORRUPT_BKPT;
7682-
memset(apOld, 0, (i+1)*sizeof(MemPage*));
7683-
goto balance_cleanup;
7684-
}else{
7684+
if( (iOff+szNew[i])<=(int)pBt->usableSize ){
76857685
memcpy(&aOvflSpace[iOff], apDiv[i], szNew[i]);
76867686
apDiv[i] = &aOvflSpace[apDiv[i]-pParent->aData];
76877687
}

src/pcache1.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ static PgHdr1 *pcache1AllocPage(PCache1 *pCache, int benignMalloc){
461461
p->page.pExtra = &p[1];
462462
p->isBulkLocal = 0;
463463
p->isAnchor = 0;
464+
p->pLruPrev = 0; /* Initializing this saves a valgrind error */
464465
}
465466
(*pCache->pnPurgeable)++;
466467
return p;

0 commit comments

Comments
 (0)