[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r18599 - in gnunet/src: include util
From: |
gnunet |
Subject: |
[GNUnet-SVN] r18599 - in gnunet/src: include util |
Date: |
Thu, 15 Dec 2011 13:40:56 +0100 |
Author: grothoff
Date: 2011-12-15 13:40:56 +0100 (Thu, 15 Dec 2011)
New Revision: 18599
Modified:
gnunet/src/include/gnunet_disk_lib.h
gnunet/src/util/container_bloomfilter.c
gnunet/src/util/disk.c
Log:
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
Modified: gnunet/src/include/gnunet_disk_lib.h
===================================================================
--- gnunet/src/include/gnunet_disk_lib.h 2011-12-15 12:05:10 UTC (rev
18598)
+++ gnunet/src/include/gnunet_disk_lib.h 2011-12-15 12:40:56 UTC (rev
18599)
@@ -368,7 +368,20 @@
GNUNET_DISK_file_open (const char *fn, enum GNUNET_DISK_OpenFlags flags,
enum GNUNET_DISK_AccessPermissions perm);
+
/**
+ * Get the size of an open file.
+ *
+ * @param fh open file handle
+ * @param size where to write size of the file
+ * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ */
+int
+GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh,
+ off_t *size);
+
+
+/**
* Creates an interprocess channel
* @param blocking creates an asynchronous pipe if set to GNUNET_NO
* @param inherit_read 1 to make read handle inheritable, 0 otherwise (NT only)
Modified: gnunet/src/util/container_bloomfilter.c
===================================================================
--- gnunet/src/util/container_bloomfilter.c 2011-12-15 12:05:10 UTC (rev
18598)
+++ gnunet/src/util/container_bloomfilter.c 2011-12-15 12:40:56 UTC (rev
18599)
@@ -456,6 +456,7 @@
off_t pos;
int i;
size_t ui;
+ off_t fsize;
GNUNET_assert (NULL != filename);
if ((k == 0) || (size == 0))
@@ -481,6 +482,21 @@
GNUNET_free (bf);
return NULL;
}
+ if (GNUNET_OK !=
+ GNUNET_DISK_file_handle_size (bf->fh, &fsize))
+ {
+ GNUNET_DISK_file_close (bf->fh);
+ GNUNET_free (bf);
+ return NULL;
+ }
+ if (fsize != size * 8LL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Size of file on disk is incorrect for this Bloom filter\n"));
+ GNUNET_DISK_file_close (bf->fh);
+ GNUNET_free (bf);
+ return NULL;
+ }
bf->filename = GNUNET_strdup (filename);
/* Alloc block */
bf->bitArray = GNUNET_malloc_large (size);
@@ -499,7 +515,7 @@
/* Read from the file what bits we can */
rbuff = GNUNET_malloc (BUFFSIZE);
pos = 0;
- while (pos < size * 8)
+ while (pos < size * 8LL)
{
int res;
@@ -507,6 +523,11 @@
if (res == -1)
{
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", bf->filename);
+ GNUNET_free (rbuff);
+ GNUNET_free (bf->filename);
+ GNUNET_DISK_file_close (bf->fh);
+ GNUNET_free (bf);
+ return NULL;
}
if (res == 0)
break; /* is ok! we just did not use that many bits
yet */
Modified: gnunet/src/util/disk.c
===================================================================
--- gnunet/src/util/disk.c 2011-12-15 12:05:10 UTC (rev 18598)
+++ gnunet/src/util/disk.c 2011-12-15 12:40:56 UTC (rev 18599)
@@ -206,6 +206,26 @@
/**
+ * Get the size of an open file.
+ *
+ * @param fh open file handle
+ * @param size where to write size of the file
+ * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ */
+int
+GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh,
+ off_t *size)
+{
+ struct stat sbuf;
+
+ if (0 != FSTAT (fh->fd, &sbuf))
+ return GNUNET_SYSERR;
+ *size = sbuf.st_size;
+ return GNUNET_OK;
+}
+
+
+/**
* Move the read/write pointer in a file
*
* @param h handle of an open file
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r18599 - in gnunet/src: include util,
gnunet <=