-
Notifications
You must be signed in to change notification settings - Fork 244
Labels
draco-rc1unit-testTickets related to the OSAL unit testing (functional and/or coverage)Tickets related to the OSAL unit testing (functional and/or coverage)
Milestone
Description
Describe the bug
memchr(x, x, -1) returns NULL on CentOS 7 (at least in one case), which within UtAssert_StringBufCompare causes the memcmp to use the max size_t which causes a SEGV.
Lines 459 to 513 in fafb045
| bool UtAssert_StringBufCompare(const char *String1, size_t String1Max, const char *String2, size_t String2Max, | |
| UtAssert_Compare_t CompareType, const char *File, uint32 Line) | |
| { | |
| char ScrubbedString1[256]; | |
| char ScrubbedString2[256]; | |
| const char *EndPtr1; | |
| const char *EndPtr2; | |
| size_t FormatLen1; | |
| size_t FormatLen2; | |
| bool Result; | |
| int Compare; | |
| /* Locate the actual end of both strings */ | |
| if (String1 == NULL) | |
| { | |
| EndPtr1 = NULL; | |
| } | |
| else | |
| { | |
| EndPtr1 = memchr(String1, 0, String1Max); | |
| } | |
| if (EndPtr1 != NULL) | |
| { | |
| FormatLen1 = EndPtr1 - String1; | |
| } | |
| else | |
| { | |
| FormatLen1 = String1Max; | |
| } | |
| if (String2 == NULL) | |
| { | |
| EndPtr2 = NULL; | |
| } | |
| else | |
| { | |
| EndPtr2 = memchr(String2, 0, String2Max); | |
| } | |
| if (EndPtr2 != NULL) | |
| { | |
| FormatLen2 = EndPtr2 - String2; | |
| } | |
| else | |
| { | |
| FormatLen2 = String2Max; | |
| } | |
| if (FormatLen1 == 0 && FormatLen2 == 0) | |
| { | |
| /* Two empty strings are considered equal */ | |
| Compare = 0; | |
| } | |
| else |
To Reproduce
Build and run this test case (others also use this pattern):
https://github.com/nasa/cFE/blob/a39b0a65fb2724692469ff492484b523fb4fa7e6/modules/config/ut-coverage/test_cfe_config.c#L138-L146
Expected behavior
No SEGV
Code snips
See above
System observed on:
- Hardware: unknown
- OS: CentOS 7
- Versions: Bundle main
Additional context
Add any other context about the problem here.
Reporter Info
Jacob Hageman - NASA/GSFC
Metadata
Metadata
Assignees
Labels
draco-rc1unit-testTickets related to the OSAL unit testing (functional and/or coverage)Tickets related to the OSAL unit testing (functional and/or coverage)