cFE icon indicating copy to clipboard operation
cFE copied to clipboard

Fix #2172, Remove last few uses of sprintf()

Open thnkslprpt opened this issue 3 years ago • 4 comments

Checklist

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 avatar Oct 18 '22 05:10 thnkslprpt

@thnkslprpt Do you know why the Functional Test check is failing?

dzbaker avatar Oct 20 '22 18:10 dzbaker

@thnkslprpt Do you know why the Functional Test check is failing?

Will figure it out and get back to you.

thnkslprpt avatar Oct 21 '22 02:10 thnkslprpt

@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

thnkslprpt avatar Oct 21 '22 02:10 thnkslprpt

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

thnkslprpt avatar Oct 31 '22 20:10 thnkslprpt