Remove remaining stray uses of sprintf()
Checklist
- [x] I reviewed the Contributing Guide.
- [x] I performed a cursory search to see if the bug report is relevant, not redundant, nor in conflict with other tickets.
Describe the bug A few stray uses of sprintf() remain in cFE (mostly in the test code, but not entirely). The simple cases will be converted to snprintf() to enforce a maximum size for the buffer being written into. A couple of cases have their own issues open already with further changes being considered, so I will probably leave those to be addressed there (https://github.com/nasa/cFE/issues/1465 and https://github.com/nasa/cFE/issues/1511)
Expected behavior No use of sprintf() in the code base (including test code).
Code snips https://github.com/nasa/cFE/blob/be88a07313ff3b579c8abaef4b4a9085e74aabdf/modules/es/fsw/src/cfe_es_cds.c#L662 https://github.com/nasa/cFE/blob/be88a07313ff3b579c8abaef4b4a9085e74aabdf/modules/cfe_testcase/src/tbl_content_access_test.c#L121
Reporter Info Avi Weiss @thnkslprpt
Previous discussion opening this issue:
I concur that snprintf has some caveats/dangers - particularly with respect to the return code and handling that properly - whereas sprintf() is a buffer overflow exploit in almost all use-cases, and should rightfully be banned.
Originally posted by @jphickey in https://github.com/nasa/cFE/issues/824#issuecomment-677851081
There are still a few stray uses of sprintf() across cFS. Should these be removed?
Yeah, that would be a good update from my point of view. Most of it's in tests which might not be a high priority, but there's a handful of flight code use still.