[Bug 203938] makefs: Coverity CID 975345, 975346: No provisions for i/o error
bugzilla-noreply at freebsd.org
bugzilla-noreply at freebsd.org
Wed Oct 21 17:40:13 UTC 2015
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=203938
Bug ID: 203938
Summary: makefs: Coverity CID 975345, 975346: No provisions for
i/o error
Product: Base System
Version: 11.0-CURRENT
Hardware: Any
OS: Any
Status: New
Severity: Affects Some People
Priority: ---
Component: bin
Assignee: freebsd-bugs at FreeBSD.org
Reporter: scdbackup at gmx.net
usr.sbin/makefs/cd9660/cd9660_debug.c
CID 975346 (#1 of 2): Ignoring number of bytes read (CHECKED_RETURN)
3. check_return: fread(void * restrict, size_t, size_t, FILE * restrict)
returns the number of bytes read, but it is ignored.
208 fread(((unsigned char*)&pttemp) + 8, 1, pttemp.length[0],
fd);
CID 975345 (#1 of 1): Ignoring number of bytes read (CHECKED_RETURN)
2. check_return: fread(void * restrict, size_t, size_t, FILE * restrict)
returns the number of bytes read, but it is ignored.
238 fread(buf, 1, CD9660_SECTOR_SIZE, fd);
--------------- Source analysis:
Indeed one should check for complete read success.
Just above the fread() calls, fseeko() failure leads to err():
200 if (fseeko(fd, CD9660_SECTOR_SIZE * sector, SEEK_SET) == -1)
201 err(1, "fseeko");
236 if (fseeko(fd, CD9660_SECTOR_SIZE * sector, SEEK_SET) == -1)
237 err(1, "fseeko");
--------------- Remedy proposal:
One should distinguish between EOF and error.
- fread(((unsigned char*)&pttemp) + 8, 1, pttemp.length[0], fd);
+ if (fread(((unsigned char*)&pttemp) + 8, 1, pttemp.length[0],
+ fd) != pttemp.length[0]) {
+ if (feof(fd))
+ err(1, "EOF on fread");
+ err(1, "Error on fread");
+ }
- fread(buf, 1, CD9660_SECTOR_SIZE, fd);
+ if (fread(buf, 1, CD9660_SECTOR_SIZE, fd) !=
+ CD9660_SECTOR_SIZE) {
+ if (feof(fd))
+ err(1, "EOF on fread");
+ err(1, "Error on fread");
+ }
--
You are receiving this mail because:
You are the assignee for the bug.
More information about the freebsd-bugs
mailing list