summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authoreschnett <eschnett@17b73243-c579-4c4c-a9d2-2d5706c11dac>2012-11-19 21:55:30 +0000
committereschnett <eschnett@17b73243-c579-4c4c-a9d2-2d5706c11dac>2012-11-19 21:55:30 +0000
commit62e7b6fe75a56cd03af37a6e4a64aa658d355466 (patch)
tree10b1710462a49d6a1e19761ef154c818dc938ea8 /src/util
parenteb5e66b09a00ec4be3389eabf65097f08e4dee29 (diff)
Check file size while reading
git-svn-id: http://svn.cactuscode.org/flesh/trunk@4915 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src/util')
-rw-r--r--src/util/ParseFile.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/util/ParseFile.c b/src/util/ParseFile.c
index a80e1df8..751bed98 100644
--- a/src/util/ParseFile.c
+++ b/src/util/ParseFile.c
@@ -316,6 +316,7 @@ int main(int argc, char *argv[])
static char *ReadFile(FILE *file, unsigned long *filesize)
{
char *buffer;
+ size_t bytes_read;
if (!file)
{
@@ -334,7 +335,13 @@ static char *ReadFile(FILE *file, unsigned long *filesize)
return NULL;
}
/* Read file into buffer and return */
- fread(buffer, *filesize, 1, file);
+ bytes_read = fread(buffer, *filesize, 1, file);
+ if (bytes_read != *filesize)
+ {
+ fprintf(stderr, "File size changed while reading.\n");
+ free(buffer);
+ return NULL;
+ }
/* Protect buffer for string operations */
buffer[*filesize] = '\0';
return buffer;