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

New GCC warnings causing build failure [-Werror=stringop-overflow=] #63

Closed
2 tasks done
thnkslprpt opened this issue Nov 6, 2022 · 1 comment · Fixed by #65
Closed
2 tasks done

New GCC warnings causing build failure [-Werror=stringop-overflow=] #63

thnkslprpt opened this issue Nov 6, 2022 · 1 comment · Fixed by #65
Assignees
Milestone

Comments

@thnkslprpt
Copy link
Contributor

Checklist

  • I reviewed the Contributing Guide.
  • I performed a cursory search to see if the bug report is relevant, not redundant, nor in conflict with other tickets.

Describe the bug
I believe these are newly triggered GCC warnings (treated as errors) that are now causing the standard FM Build + Run workflow to fail.

In function ‘strncpy’,
    inlined from ‘FM_ChildDirListPktCmd’ at /home/runner/work/FM/FM/apps/fm/fsw/src/fm_child.c:1227:25:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10: error: ‘__builtin___strncpy_chk’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/FM/FM/apps/fm/fsw/src/fm_child.c: In function ‘FM_ChildDirListPktCmd’:
/home/runner/work/FM/FM/apps/fm/fsw/src/fm_child.c:1221:35: note: length computed here
 1221 |                     EntryLength = strlen(OS_DIRENTRY_NAME(DirEntry));
      |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
In function ‘strncat’,
    inlined from ‘FM_ChildDirListPktCmd’ at /home/runner/work/FM/FM/apps/fm/fsw/src/fm_child.c:1234:25:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:136:10: error: ‘__builtin___strncat_chk’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
  136 |   return __builtin___strncat_chk (__dest, __src, __len, __bos (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/FM/FM/apps/fm/fsw/src/fm_child.c: In function ‘FM_ChildDirListPktCmd’:
/home/runner/work/FM/FM/apps/fm/fsw/src/fm_child.c:1221:35: note: length computed here
 1221 |                     EntryLength = strlen(OS_DIRENTRY_NAME(DirEntry));
      |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
In function ‘strncpy’,
    inlined from ‘FM_ChildDirListFileLoop’ at /home/runner/work/FM/FM/apps/fm/fsw/src/fm_child.c:1450:21:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10: error: ‘__builtin___strncpy_chk’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/FM/FM/apps/fm/fsw/src/fm_child.c: In function ‘FM_ChildDirListFileLoop’:
/home/runner/work/FM/FM/apps/fm/fsw/src/fm_child.c:1434:31: note: length computed here
 1434 |                 EntryLength = strlen(OS_DIRENTRY_NAME(DirEntry));
      |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

To Reproduce
Run the Build + Run GitHub Action on the current main branch FM source code.

Expected behavior
Build + Run workflow should run without errors.

Reporter Info
Avi @thnkslprpt

@jphickey
Copy link
Contributor

Looking at the code, it does indeed seem suspicious - but there is a length check against OS_MAX_PATH_LEN that prevents anything from overflowing a buffer:

FM/fsw/src/fm_child.c

Lines 1221 to 1228 in 23b792d

EntryLength = strlen(OS_DIRENTRY_NAME(DirEntry));
/* Verify combined directory plus filename length */
if ((PathLength + EntryLength) < OS_MAX_PATH_LEN)
{
/* Add filename to directory listing telemetry packet */
strncpy(ListEntry->EntryName, OS_DIRENTRY_NAME(DirEntry), EntryLength);
ListEntry->EntryName[EntryLength] = '\0';

Recommendation:

  • Use sizeof(ListEntry->EntryName) and sizeof(LogicalName), respectively, rather than assuming OS_MAX_PATH_LEN
  • Use more appropriate string copy routine - either CFE_SB_MessageStringSet() or simply memcpy() (which is safe if the lengths have all been verified, as they will have been here)

jphickey added a commit to jphickey/FM that referenced this issue Nov 14, 2022
Call "strncpy" with the size parameter indicating the size of the
destination buffer, rather than the input string length.

A buffer overflow was avoided due to a length check already in the code,
but calling the function properly should avoid a warning.
jphickey added a commit to jphickey/FM that referenced this issue Nov 14, 2022
Call "strncpy" with the size parameter indicating the size of the
destination buffer, rather than the input string length.

A buffer overflow was avoided due to a length check already in the code,
but calling the function properly should avoid a warning.
dzbaker added a commit that referenced this issue Nov 17, 2022
@dmknutsen dmknutsen added this to the Draco milestone Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants