Bug 203937

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

Description scdbackup 2015-10-21 16:58:36 UTC
usr.sbin/makefs/cd9660/cd9660_eltorito.c

CID 975347 : Unchecked return value from library (CHECKED_RETURN)
   5. check_return: Calling fseek(fd, 32UL - strlen(part_type) - 1UL, 1)
   without checking return value.

575        fseek(fd, 32 - strlen(part_type) - 1, SEEK_CUR);

CID 975348: Unchecked return value from library (CHECKED_RETURN)
   33. check_return: Calling fseek(fd, 510L, 0) without checking return

639     fseek(fd, 0x1fe, SEEK_SET);

(Ouch, an ISO producer which does not work on sequential file
 objects. That's quite inconvenient for users.)

--------------- Source analysis:

There are three fseek() with unchecked result:

In cd9660_write_apm_partition_entry():

573     fseek(fd, 32 - strlen(part_name) - 1, SEEK_CUR);

575        fseek(fd, 32 - strlen(part_type) - 1, SEEK_CUR);

In cd9660_write_boot():

639     fseek(fd, 0x1fe, SEEK_SET);

Failed fseeko() is handled by calling err(), which exits the process:

554     if (fseeko(fd, (off_t)(idx + 1) * sector_size, SEEK_SET) == -1)
555             err(1, "fseeko");

--------------- Remedy proposal:

Bail out by err(), too:

-       fseek(fd, 32 - strlen(part_name) - 1, SEEK_CUR);
+       if (fseek(fd, 32 - strlen(part_name) - 1, SEEK_CUR) == -1)
+               err(1, "fseek for APM partition");

-       fseek(fd, 32 - strlen(part_type) - 1, SEEK_CUR);
+       if (fseek(fd, 32 - strlen(part_type) - 1, SEEK_CUR) == -1)
+               err(1, "fseek for APM partition");

-               fseek(fd, 0x1fe, SEEK_SET);
+               if (fseek(fd, 0x1fe, SEEK_SET) == -1)
+                       err(1, "fseek for MBR partition");
Comment 1 Enji Cooper freebsd_committer freebsd_triage 2015-10-25 22:12:58 UTC
Bulk taking makefs bugs.
Comment 2 Enji Cooper freebsd_committer freebsd_triage 2017-11-05 20:47:20 UTC
Releasing bugs back to the pool.