Bug 203938 - makefs: Coverity CID 975345, 975346: No provisions for i/o error
Summary: makefs: Coverity CID 975345, 975346: No provisions for i/o error
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-21 17:40 UTC by scdbackup
Modified: 2023-04-18 17:47 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description scdbackup 2015-10-21 17:40:13 UTC
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");
+                }
Comment 1 Enji Cooper freebsd_committer freebsd_triage 2015-10-25 22:13:00 UTC
Bulk taking makefs bugs.
Comment 2 Enji Cooper freebsd_committer freebsd_triage 2017-11-05 20:47:21 UTC
Releasing bugs back to the pool.