nasa / cFE

The Core Flight System (cFS) Core Flight Executive (cFE)
Apache License 2.0
402 stars 198 forks source link

address sanitizer option detect segv in es_UT.c #2553

Closed avan989 closed 1 week ago

avan989 commented 2 months ago

Describe the bug When run with address sanitizer option the following error occurs:

AddressSanitizer:DEADLYSIGNAL
=================================================================
==9380==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f63fa6e4926 bp 0x7ffe746f7540 sp 0x7ffe746f6c88 T0)
==9380==The signal is caused by a READ memory access.
==9380==Hint: address points to the zero page.
    #0 0x7f63fa6e4926 in __sanitizer::internal_strlen(char const*) ../../../../src/libsanitizer/sanitizer_common/sanitizer_libc.cpp:167
    #1 0x7f63fa677f27 in printf_common ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors_format.inc:490
    #2 0x7f63fa679f75 in __interceptor_vsnprintf ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:1664
    #3 0x5631161e6d00 in CFE_ES_SysLog_vsnprintf /home/vboxuser/Desktop/cFS/cfe/modules/es/fsw/src/cfe_es_syslog.c:390
    #4 0x5631161963d8 in ES_UT_SysLog_snprintf /home/vboxuser/Desktop/cFS/cfe/modules/es/ut-coverage/es_UT.c:226
    #5 0x5631161b8431 in TestAPI /home/vboxuser/Desktop/cFS/cfe/modules/es/ut-coverage/es_UT.c:4559
    #6 0x56311620df71 in UtTest_Run /home/vboxuser/Desktop/cFS/osal/ut_assert/src/uttest.c:172
    #7 0x56311620e9be in OS_Application_Run /home/vboxuser/Desktop/cFS/osal/ut_assert/src/utbsp.c:230
    #8 0x563116228d05 in main /home/vboxuser/Desktop/cFS/osal/src/bsp/generic-linux/src/bsp_start.c:244
    #9 0x7f63fa41b082 in __libc_start_main ../csu/libc-start.c:308
    #10 0x563116195b3d in _start (/home/vboxuser/Desktop/cFS/build/exe/cpu1/coverage-es-ALL-testrunner+0x41b3d)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV ../../../../src/libsanitizer/sanitizer_common/sanitizer_libc.cpp:167 in __sanitizer::internal_strlen(char const*)
==9380==ABORTING

The cause seems to be that one of the coverage tests is trying to pass a null to an snprintf:

https://github.com/nasa/cFE/blob/28a58203a56ed7c1512c79c961fadeddb5bbb7bb/modules/es/ut-coverage/es_UT.c#L4559

To Reproduce Steps to reproduce the behavior:

  1. Add in the following compiler options: add_compile_options(-fsanitize=address -g) add_link_options(-fsanitize=address)

  2. Do make install ENABLE_UNIT_TESTS=true

  3. Run test

Expected behavior Error out.

Code snips If applicable, add references to the software.

System observed on:

Additional context Add any other context about the problem here.

Reporter Info Full name and company/organization if applicable Anh Van. GSFC