summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Hohmuth <sideral@rockbox.org>2011-08-04 10:21:40 +0000
committerMichael Hohmuth <sideral@rockbox.org>2011-08-04 10:21:40 +0000
commit4cb473562e4602ce92c331631b491c910dea536c (patch)
treead5bad7f91bd4562ceb39a6af0a4455714eb77c1
parent95c1e7d8b07ecd529da3ab747fcf5ee9a1f2b230 (diff)
downloadrockbox-4cb473562e4602ce92c331631b491c910dea536c.tar.gz
rockbox-4cb473562e4602ce92c331631b491c910dea536c.zip
Database: Fix memory-area bounds checking during database reload.
Check free space before reading new data from disk, and do not forget to account for the RAM-cache header. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30246 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/tagcache.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c
index c6a08fea4f..7f33db7cf5 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -3905,7 +3905,7 @@ static bool load_tagcache(void)
3905{ 3905{
3906 struct tagcache_header *tch; 3906 struct tagcache_header *tch;
3907 struct master_header tcmh; 3907 struct master_header tcmh;
3908 long bytesleft = tc_stat.ramcache_allocated; 3908 long bytesleft = tc_stat.ramcache_allocated - sizeof(struct ramcache_header);
3909 struct index_entry *idx; 3909 struct index_entry *idx;
3910 int rc, fd; 3910 int rc, fd;
3911 char *p; 3911 char *p;
@@ -3943,6 +3943,14 @@ static bool load_tagcache(void)
3943 /* Load the master index table. */ 3943 /* Load the master index table. */
3944 for (i = 0; i < tcmh.tch.entry_count; i++) 3944 for (i = 0; i < tcmh.tch.entry_count; i++)
3945 { 3945 {
3946 bytesleft -= sizeof(struct index_entry);
3947 if (bytesleft < 0)
3948 {
3949 logf("too big tagcache.");
3950 close(fd);
3951 return false;
3952 }
3953
3946 /* DEBUG: After tagcache commit and dircache rebuild, hdr-sturcture 3954 /* DEBUG: After tagcache commit and dircache rebuild, hdr-sturcture
3947 * may become corrupt. */ 3955 * may become corrupt. */
3948 rc = ecread_index_entry(fd, idx); 3956 rc = ecread_index_entry(fd, idx);
@@ -3953,15 +3961,6 @@ static bool load_tagcache(void)
3953 return false; 3961 return false;
3954 } 3962 }
3955 3963
3956 bytesleft -= sizeof(struct index_entry);
3957 if (bytesleft < 0 ||
3958 ((long)idx - (long)ramcache_hdr->indices) >= tc_stat.ramcache_allocated)
3959 {
3960 logf("too big tagcache.");
3961 close(fd);
3962 return false;
3963 }
3964
3965 idx++; 3964 idx++;
3966 } 3965 }
3967 3966