Fix #2172, Remove last few uses of sprintf()
Checklist
- [x] I reviewed the Contributing Guide.
- [x] I signed and emailed the appropriate Contributor License Agreement to [email protected] and copied [email protected].
Describe the contribution
- Fixes #2172
- Use of sprintf() swapped for snprintf() removing a source of potential buffer overruns.
2 other cases already have their own issues open with further changes being considered, and have not been updated with this PR at this stage (https://github.com/nasa/cFE/issues/1465 and https://github.com/nasa/cFE/issues/1511).
Testing performed Standard cFS build tests (covered the fsw change but not test code change).
Expected behavior changes No impact on behavior expected.
System(s) tested on Intel(R) Celeron(R) N4100 CPU @ 1.10GHz x86_64 Debian GNU/Linux 11 (bullseye) cFE v7.0.0-rc4+dev193
Contributor Info Avi Weiss @thnkslprpt
@thnkslprpt Do you know why the Functional Test check is failing?
@thnkslprpt Do you know why the Functional Test check is failing?
Will figure it out and get back to you.
@thnkslprpt Do you know why the Functional Test check is failing?
OK it seems to be passing now. The 2nd parameter (bufsz) of snprintf() was decaying to a pointer causing the function to print an empty string. By using CFE_MISSION_ES_CDS_MAX_FULL_NAME_LEN as the bufsz parameter, which is the size of the passed-in FullCDSName for the CFE_ES_FormCDSName() fuction, the snprintf() functions correctly.
Ref for size of FullCDSName parameter: https://github.com/nasa/cFE/blob/be88a07313ff3b579c8abaef4b4a9085e74aabdf/modules/es/fsw/src/cfe_es_cds.h#L536
This change is good, however we should also not forget about the other one (as noted, my suggestion is to remove the broken API, clean up the caller).
No worries Joe. https://github.com/nasa/cFE/issues/2193