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:
Jonathan Kamens 2023-09-29 14:21:20 -04:00 committed by Fufu Fang
parent 7363adaf12
commit c532661d29
1 changed files with 5 additions and 9 deletions

View File

@ -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;
}