diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-12-15 12:40:56 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-12-15 12:40:56 +0000 |
commit | 2fa26e646e1cfdba15d02ce3428ed72e93d73a09 (patch) | |
tree | 3ec0ec95cb89d3709575190aa865a469b9a9bee5 /src/util/container_bloomfilter.c | |
parent | 00398b12d163e69befd2732729440e5d21ae0207 (diff) | |
download | gnunet-2fa26e646e1cfdba15d02ce3428ed72e93d73a09.tar.gz gnunet-2fa26e646e1cfdba15d02ce3428ed72e93d73a09.zip |
extra error checking in Bloom filter to check that the size of the file on disk corresponds to the expected size for the given filter
Diffstat (limited to 'src/util/container_bloomfilter.c')
-rw-r--r-- | src/util/container_bloomfilter.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/util/container_bloomfilter.c b/src/util/container_bloomfilter.c index 31e777dc3..0349c32ac 100644 --- a/src/util/container_bloomfilter.c +++ b/src/util/container_bloomfilter.c | |||
@@ -456,6 +456,7 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, | |||
456 | off_t pos; | 456 | off_t pos; |
457 | int i; | 457 | int i; |
458 | size_t ui; | 458 | size_t ui; |
459 | off_t fsize; | ||
459 | 460 | ||
460 | GNUNET_assert (NULL != filename); | 461 | GNUNET_assert (NULL != filename); |
461 | if ((k == 0) || (size == 0)) | 462 | if ((k == 0) || (size == 0)) |
@@ -481,6 +482,21 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, | |||
481 | GNUNET_free (bf); | 482 | GNUNET_free (bf); |
482 | return NULL; | 483 | return NULL; |
483 | } | 484 | } |
485 | if (GNUNET_OK != | ||
486 | GNUNET_DISK_file_handle_size (bf->fh, &fsize)) | ||
487 | { | ||
488 | GNUNET_DISK_file_close (bf->fh); | ||
489 | GNUNET_free (bf); | ||
490 | return NULL; | ||
491 | } | ||
492 | if (fsize != size * 8LL) | ||
493 | { | ||
494 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
495 | _("Size of file on disk is incorrect for this Bloom filter\n")); | ||
496 | GNUNET_DISK_file_close (bf->fh); | ||
497 | GNUNET_free (bf); | ||
498 | return NULL; | ||
499 | } | ||
484 | bf->filename = GNUNET_strdup (filename); | 500 | bf->filename = GNUNET_strdup (filename); |
485 | /* Alloc block */ | 501 | /* Alloc block */ |
486 | bf->bitArray = GNUNET_malloc_large (size); | 502 | bf->bitArray = GNUNET_malloc_large (size); |
@@ -499,7 +515,7 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, | |||
499 | /* Read from the file what bits we can */ | 515 | /* Read from the file what bits we can */ |
500 | rbuff = GNUNET_malloc (BUFFSIZE); | 516 | rbuff = GNUNET_malloc (BUFFSIZE); |
501 | pos = 0; | 517 | pos = 0; |
502 | while (pos < size * 8) | 518 | while (pos < size * 8LL) |
503 | { | 519 | { |
504 | int res; | 520 | int res; |
505 | 521 | ||
@@ -507,6 +523,11 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, | |||
507 | if (res == -1) | 523 | if (res == -1) |
508 | { | 524 | { |
509 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", bf->filename); | 525 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", bf->filename); |
526 | GNUNET_free (rbuff); | ||
527 | GNUNET_free (bf->filename); | ||
528 | GNUNET_DISK_file_close (bf->fh); | ||
529 | GNUNET_free (bf); | ||
530 | return NULL; | ||
510 | } | 531 | } |
511 | if (res == 0) | 532 | if (res == 0) |
512 | break; /* is ok! we just did not use that many bits yet */ | 533 | break; /* is ok! we just did not use that many bits yet */ |