Bug 203937 - makefs: Coverity CID 975347, 975348: No provisions for i/o error
Summary: makefs: Coverity CID 975347, 975348: No provisions for i/o error
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs mailing list
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2015-10-21 16:58 UTC by scdbackup
Modified: 2019-01-26 15:13 UTC (History)
2 users (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 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 2015-10-25 22:12:58 UTC
Bulk taking makefs bugs.
Comment 2 Enji Cooper freebsd_committer 2017-11-05 20:47:20 UTC
Releasing bugs back to the pool.