diff options
-rw-r--r-- | apps/tagcache.c | 19 |
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 | ||