aboutsummaryrefslogtreecommitdiff
path: root/src/bucket.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2018-05-19 17:19:20 +0300
committerSergey Poznyakoff <gray@gnu.org>2018-05-19 17:28:35 +0300
commit2ed5403c82833c8977171972b6779ec92bcc086f (patch)
treed7c4b170b8ecc08e32e46653e07f45643c929669 /src/bucket.c
parentd228fddf791187b44839b8d8c40478f3577812a2 (diff)
downloadgdbm-2ed5403c82833c8977171972b6779ec92bcc086f.tar.gz
gdbm-2ed5403c82833c8977171972b6779ec92bcc086f.tar.bz2
Improve error checking
* src/bucket.c (_gdbm_get_bucket): Improve validation. * src/fullio.c (_gdbm_full_read,_gdbm_full_write): Don't overwrite an already set error. * src/gdbm.h.in (GDBM_WRONG_OFF_T): Merge with GDBM_BAD_FILE_OFFSET. (GDBM_BAD_HEADER): New error code. * src/gdbmdump.c (_gdbm_dump_ascii): Check for database error code. * src/gdbmerrno.c (gdbm_errlist): Add GDBM_BAD_HEADER * src/gdbmopen.c (validate_header: Imporve logic. (_gdbm_init_cache): Initialize bucket_cache * src/gdbmseq.c (gdbm_firstkey): Check return value from _gdbm_get_bucket. * src/mmap.c (_gdbm_mapped_remap): Bail out if current position is bigger than file size.
Diffstat (limited to 'src/bucket.c')
-rw-r--r--src/bucket.c9
1 files changed, 2 insertions, 7 deletions
diff --git a/src/bucket.c b/src/bucket.c
index 6def504..ce1915a 100644
--- a/src/bucket.c
+++ b/src/bucket.c
@@ -72,8 +72,6 @@ _gdbm_get_bucket (GDBM_FILE dbf, int dir_index)
/* Is that one is not already current, we must find it. */
if (dbf->cache_entry->ca_adr != bucket_adr)
{
- size_t max_bucket_elts;
-
/* Look in the cache. */
for (index = 0; index < dbf->cache_size; index++)
{
@@ -120,13 +118,10 @@ _gdbm_get_bucket (GDBM_FILE dbf, int dir_index)
return -1;
}
/* Validate the bucket */
- max_bucket_elts =
- (dbf->header->bucket_size - sizeof(hash_bucket))
- / sizeof(bucket_element) + 1;
if (!(dbf->bucket->count >= 0
&& dbf->bucket->av_count >= 0
- && dbf->bucket->count <= max_bucket_elts
- && dbf->bucket->av_count <= max_bucket_elts))
+ && dbf->bucket->count <= dbf->header->bucket_elems
+ && dbf->bucket->av_count <= dbf->header->bucket_elems))
{
GDBM_SET_ERRNO (dbf, GDBM_BAD_BUCKET, TRUE);
return -1;

Return to:

Send suggestions and report system problems to the System administrator.