Regarding FatFS Coverity Issues on RTEMS

Hey @JoelSherrill @gedare ,
I went through the reported Coverity findings and traced the relevant code paths in the current FatFs integration. I have included a brief overview of my analysis and attached relevant pdfs for your reference. Let me know if you have any questions. I have replied accordingly for the related issue.

I would advice contacting the author if he is available through mailing : user5@elm-chan.org, Since this was the only source of contact I could find for now.

The RTEMS Issue which was detected was already fixed by commit 01f88b058f which added an explicit cast (uint32_t) presented below

inode_hash ^= fno->fsize ^ ((uint32_t) fno->fdate << 16) ^ fno->ftime;

  • Coverity false positives: 1668653, 1668652, 1668650, 1668648, 1668646, 1668644
  • RTEMS issue, already fixed: 1668651
  • Upstream FatFs issues: 1668649, 1668647, 1668645
CID Classification Brief overview
1668653 Coverity false positive f_getcwd() passes a partially initialized FFOBJID, but the uninitialized fields reported by Coverity are only accessed in the exFAT path, while the reported path is FAT/FAT32.
1668652 Coverity false positive f_rename() copies DIR structures containing an uninitialized obj.id, but id is not consumed along this execution path; validate() is not called by follow_path().
1668651 RTEMS issue – already fixed The signed-extension warning on fdate << 16 was a genuine RTEMS integration issue; the explicit (uint32_t) cast has already been added in a later RTEMS commit.
1668650 Coverity false positive create_partition() can legitimately wrap the BYTE variable n_hd from 128 to 0 when doubling it to 256, making the n_hd == 0 fallback reachable.
1668649 Upstream FatFs issue f_rename() ignores the return value of get_ldnumber() for the new path, so an invalid logical drive can go unchecked instead of returning FR_INVALID_DRIVE.
1668648 Coverity false positive f_getfree() passes a partially initialized FFOBJID, but the reported uninitialized exFAT fields are not accessed because the call is explicitly inside the FAT12 path.
1668647 Upstream FatFs issue In f_unlink(), sdj.obj.n_frag is not initialized before an exFAT get_fat() path can consume it when stat == 0; objsize is initialized and n_cont is not reachable in the reported state.
1668646 Coverity false positive get_fileinfo() can write at most 11 SFN characters plus one . (12 characters); altname has 13 elements, leaving index 12 for the terminating NUL.
1668645 Upstream FatFs issue f_mkdir() ignores the return value of remove_chain() when cleaning up an allocated cluster after directory creation fails; cleanup can itself return disk/internal errors.
1668644 Coverity false positive obj->objsize - 1 can technically wrap when objsize == 0, but in that state clen cannot be used by the stat == 2 branch, so the overflow has no behavioral effect.

I
Investigation_CID_1668651.pdf (152.6 KB)
Investigation_CID_1668649.pdf (159.1 KB)
Investigation_CID_1668647.pdf (175.9 KB)
Investigation_CID_1668645.pdf (141.2 KB)

The other Investigation Reports are attached below
Investigation_CID_1668653.pdf (141.6 KB)
Investigation_CID_1668652.pdf (172.0 KB)
Investigation_CID_1668650.pdf (174.2 KB)
Investigation_CID_1668648.pdf (128.5 KB)
Investigation_CID_1668646.pdf (143.7 KB)

Investigation_CID_1668644.pdf (168.4 KB)

@amar You mentioned that the fatfs author is on Discord. Could you let him know about this post?

I don’t mind marking false positives from Coverity but their opinion is needed Similarly, they need to be aware of anything that is an issue upstream. RTEMS can pick up a new version when they are fixed. Or as they are fixed. Merging an update to fatfs will trigger a Coverity run as does any other update.

I haven’t taken a close look yet, but if Coverity is pointing at ff.c or ff*.c/h then this is a part of the FatFS source stack, not the code produced for GSoC. Would that be referred upstream??? or whatever you’d call Elm Chan?

(sorry, I just read the original post, yeah not much to add I’m afraid)

Exactly, the findings for ff.c and ff.h are from the FatFS source stack which was imported into RTEMS instead of the GSOC code. I have classified the potential FatFS upstream issues, so contacting the author i.e Elm Chan is the right choice here.
We had marked the issues which were false positives earlier