Bug 203938

Summary: makefs: Coverity CID 975345, 975346: No provisions for i/o error
Product: Base System Reporter: scdbackup
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Open ---    
Severity: Affects Some People CC: emaste
Priority: ---    
Version: CURRENT   
Hardware: Any   
OS: Any   
See Also: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=203937

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.