Add missing error-checking for return value of fread
Several calls to fread were missing checks to ensure that the expected amount of data was read.
This commit is contained in:
parent
7363adaf12
commit
c532661d29
14
src/cache.c
14
src/cache.c
|
@ -163,15 +163,11 @@ static int Meta_read(Cache *cf)
|
|||
return EIO;
|
||||
}
|
||||
|
||||
fread(&cf->time, sizeof(long), 1, fp);
|
||||
fread(&cf->content_length, sizeof(off_t), 1, fp);
|
||||
fread(&cf->blksz, sizeof(int), 1, fp);
|
||||
fread(&cf->segbc, sizeof(long), 1, fp);
|
||||
|
||||
/*
|
||||
* Error checking for fread
|
||||
*/
|
||||
if (ferror(fp)) {
|
||||
if (sizeof(long) != fread(&cf->time, sizeof(long), 1, fp) ||
|
||||
sizeof(off_t) != fread(&cf->content_length, sizeof(off_t), 1, fp) ||
|
||||
sizeof(int) != fread(&cf->blksz, sizeof(int), 1, fp) ||
|
||||
sizeof(long) != fread(&cf->segbc, sizeof(long), 1, fp) ||
|
||||
ferror(fp)) {
|
||||
lprintf(error, "error reading core metadata!\n");
|
||||
return EIO;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue