aboutsummaryrefslogtreecommitdiff
path: root/src/btree.c
diff options
context:
space:
mode:
authordanielk1977 <danielk1977@noemail.net>2008-09-10 17:53:35 +0000
committerdanielk1977 <danielk1977@noemail.net>2008-09-10 17:53:35 +0000
commit67fd7a9a9828dc18d8ccdbc73ac4dc2946ff9f52 (patch)
tree142b25ed59aecaa9fc370da6b8f13c6de3a97c29 /src/btree.c
parent9f580ad886bd2c3eac25e0e9cfab2981bd7e4df1 (diff)
downloadsqlite-67fd7a9a9828dc18d8ccdbc73ac4dc2946ff9f52.tar.gz
sqlite-67fd7a9a9828dc18d8ccdbc73ac4dc2946ff9f52.zip
Fix some trivial cases where database corruption was causing an error code other than SQLITE_CORRUPT to be returned. (CVS 5690)
FossilOrigin-Name: 89fda074f6b4959c32f1083badba3c73cffb4995
Diffstat (limited to 'src/btree.c')
-rw-r--r--src/btree.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/btree.c b/src/btree.c
index 7ccb2d6c8..41ffd57e4 100644
--- a/src/btree.c
+++ b/src/btree.c
@@ -9,7 +9,7 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
-** $Id: btree.c,v 1.510 2008/09/10 14:45:58 danielk1977 Exp $
+** $Id: btree.c,v 1.511 2008/09/10 17:53:36 danielk1977 Exp $
**
** This file implements a external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information.
@@ -1086,6 +1086,17 @@ int sqlite3BtreeGetPage(
}
/*
+** Return the size of the database file in pages. Or return -1 if
+** there is any kind of error.
+*/
+static int pagerPagecount(Pager *pPager){
+ int rc;
+ int nPage;
+ rc = sqlite3PagerPagecount(pPager, &nPage);
+ return (rc==SQLITE_OK?nPage:-1);
+}
+
+/*
** Get a page from the pager and initialize it. This routine
** is just a convenience wrapper around separate calls to
** sqlite3BtreeGetPage() and sqlite3BtreeInitPage().
@@ -1099,7 +1110,7 @@ static int getAndInitPage(
int rc;
assert( sqlite3_mutex_held(pBt->mutex) );
assert( !pParent || pParent->isInit );
- if( pgno==0 ){
+ if( pgno==0 || pgno>pagerPagecount(pBt->pPager) ){
return SQLITE_CORRUPT_BKPT;
}
rc = sqlite3BtreeGetPage(pBt, pgno, ppPage, 0);
@@ -2029,17 +2040,6 @@ trans_begun:
return rc;
}
-/*
-** Return the size of the database file in pages. Or return -1 if
-** there is any kind of error.
-*/
-static int pagerPagecount(Pager *pPager){
- int rc;
- int nPage;
- rc = sqlite3PagerPagecount(pPager, &nPage);
- return (rc==SQLITE_OK?nPage:-1);
-}
-
#ifndef SQLITE_OMIT_AUTOVACUUM
@@ -3184,7 +3184,7 @@ static int accessPayload(
}
if( offset+amt > nKey+pCur->info.nData ){
/* Trying to read or write past the end of the data is an error */
- return SQLITE_ERROR;
+ return SQLITE_CORRUPT_BKPT;
}
/* Check if data must be read/written to/from the btree page itself. */