Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format truncation warning in UtAssert_DoTestSegmentReport (Ubuntu 20.04) #1241

Open
chillfig opened this issue Mar 29, 2022 · 1 comment
Open
Labels
unit-test Tickets related to the OSAL unit testing (functional and/or coverage)

Comments

@chillfig
Copy link
Contributor

chillfig commented Mar 29, 2022

Describe the bug
A ubuntu 20.04 release job reveals that the current implementation of osal/ut_assert/CMakeFiles/ut_assert.dir/src/utassert.c/UtAssert_DoTestSegmentReport potentially truncates the output to fit in ReportBuffer.

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://github.com/chillfig/CF/actions/runs/2054990660
  2. Click on Build (ubuntu-20.04, release)
  3. Scroll down to lines 105-126 of the "Make Install" job

Expected behavior
Passing workflow

Code snips

Screen Shot 2022-03-29 at 1 17 54 PM

System observed on:
Ubuntu 20.04

Additional context
ReportBuffer is currently implemented with size 144. UtAssert_DoTestSegmentReport may truncate the output to fit in the buffer. Attempting to write snprintf with 8 uint32 variables, 1 character array of size 64 named SegmentName, and 56 bytes of hard-coded strings (e.g. "TOTAL", "PASS", "FAIL", "MIR").

Reporter Info
Justin Figueroa, ASRC Federal

@skliper skliper added the unit-test Tickets related to the OSAL unit testing (functional and/or coverage) label Mar 29, 2022
@skliper
Copy link
Contributor

skliper commented Mar 29, 2022

Note this is a format truncation warning, not a buffer overflow since snprintf limits the write by the size of the buffer. nasa/cFE#1097 actually requests disabling this sort of warning since it's why we use snprintf in the first place (intentional truncation). Updating title to reflect this. Code snip:

snprintf(ReportBuffer, sizeof(ReportBuffer),
"%02u %-20s TOTAL::%-4u PASS::%-4u FAIL::%-4u MIR::%-4u TSF::%-4u TTF::%-4u WARN::%-4u\n",
(unsigned int)TestCounters->TestSegmentCount, SegmentName, (unsigned int)TestCounters->TotalTestCases,
(unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_PASS],
(unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_FAILURE],
(unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_MIR],
(unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_TSF],
(unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_TTF],
(unsigned int)TestCounters->CaseCount[UTASSERT_CASETYPE_WARN]);

@skliper skliper changed the title Potential buffer overflow with unit test asserts in osal Format truncation warning in UtAssert_DoTestSegmentReport (Ubuntu 20.04) Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unit-test Tickets related to the OSAL unit testing (functional and/or coverage)
Projects
None yet
Development

No branches or pull requests

2 participants