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

Fix #861, compile time assert for sockaddr size #908

Merged

Conversation

jphickey
Copy link
Contributor

Describe the contribution
OSAL provides an abstract buffer for socket addresses, independent of the underlying implementation. The size of this buffer is
configurable by the user via compile-time options.

This adds a CompileTimeAssert to confirm that the size of this abstract buffer is large enough to store any of the enabled
address types. This also removes the need for runtime tests.

Fixes #861

Testing performed
Build and sanity test, run unit tests

Expected behavior changes
This change means that the OS_SOCKADDR_MAX_LEN must be configured large enough for all enabled address types. For instance, ipv6 addresses are likely to be larger than ipv4 addresses in the implementation. It is therefore possible to se OS_SOCKADDR_MAX_LEN large enough for ipv4 but not large enough for ipv6.

A configuration such as this used to work if the runtime code only used ipv4 addresses. If runtime code used ipv6 address, it would fail at runtime. With this change, a configuration such as this will fail to compile, and enforce that the abstract size is large enough for any/all enabled address types, regardless of what is actually used.

System(s) tested on
Ubuntu 20.04

Contributor Info - All information REQUIRED for consideration of pull request
Joseph Hickey, Vantage Systems, Inc.

OSAL provides an abstract buffer for socket addresses, independent
of the underlying implementation.  The size of this buffer is
configurable by the user via compile-time options.

This adds a CompileTimeAssert to confirm that the size of this
abstract buffer is large enough to store any of the enabled
address types. This also removes the need for runtime tests.
@jphickey jphickey added the CCB:Ready Pull request is ready for discussion at the Configuration Control Board (CCB) label Mar 15, 2021
@skliper
Copy link
Contributor

skliper commented Mar 17, 2021

Disregard my comment at the CCB, doesn't make much sense. I'm OK with ==, assumes no funny padding.

@jphickey
Copy link
Contributor Author

OK - I took a second look and realized that it indeed needs to be == ... if it was >= then it would defeat the purpose - this means that one or more of the struct members were bigger than the generic field.

The only possible issue is that if there is some extra compiler-added padding, you might have a situation where the size was technically "big enough" but still fails the assert, but then you just have to increase the size a bit to make it a multiple of alignment, which should be common practice anyway (no big deal).

@astrogeco astrogeco changed the base branch from main to integration-candidate March 19, 2021 03:18
@astrogeco astrogeco added IC:2021-03-23 and removed CCB:Ready Pull request is ready for discussion at the Configuration Control Board (CCB) labels Mar 19, 2021
@astrogeco astrogeco merged commit 03927ee into nasa:integration-candidate Mar 19, 2021
astrogeco added a commit to astrogeco/osal that referenced this pull request Mar 22, 2021
astrogeco added a commit to nasa/cFS that referenced this pull request Mar 22, 2021
nasa/osal#914 - Fix #752, Utilize UTASSERT_CASETYPE_NA to report OS_ERR_NOT_IMPLEMENTED
nasa/osal#898 - Fix #857, correct interval calculation in DoSelect
nasa/osal#909 - Fix #862, comments describing select after connect
nasa/osal#902 - Fix #858, add check for EAGAIN in addition to EINTR
nasa/osal#908 - Fix #861, compile time assert for sockaddr size
nasa/osal#910 - Fix #863, check/report fcntl status
nasa/osal#897 - Fix #855, Add assert for FD_SET_SIZE in relation to OSAL_set
nasa/osal#903 - Fix #867, better error translation for ESPIPE errno
nasa/osal#840 - Fix #416, add shell functional test
nasa/osal#901 - Fix #869, rename OS_U32ValueWrapper_t
nasa/osal#900 - Fix #876, break up logic in return statement
nasa/osal#906 - Fix #886, return moduleInfoGet error
nasa/osal#907 - Fix #889, report timer_gettime error
nasa/osal#899 - Fix #883, remove unreachable test
nasa/osal#905 - Fix #882, make module comment same as other services
astrogeco added a commit to nasa/cFS that referenced this pull request Mar 22, 2021
nasa/cFE#1243 v6.8.0-rc1+dev436

  nasa/cFE#1225, Add coverage test fix
  nasa/cFE#1218, Adds a local definition of `SOFTWARE_BIG/LITTLE_BIT_ORDER` directly inside `cfe_endian.h` to provide a compatible symbol for apps that still require this. This allows CFE to build and run successfully when OSAL stops providing this in `common_types.h`.
  nasa/cFE#1193, Removes incorrect statements from Application Developers Guide
  nasa/cFE#1235, Fixes truncation handling on vsnprintf error by adding a cast to avoid implicit conversion
  nasa/cFE#1220, Clarify the documentation on SB MsgId regarding requirements for command and telemetry messages
  nasa/cFE#1230, Avoids undefined behavior and resolves static analysis warnings by casting `isspace` input to `unsigned char`.
  nasa/cFE#1231, Updates message module and msgid v1, `CFE_MSG_SetMsgId`, to use mask instead of cast to alter value. Resolves static analysis warning.
  nasa/cFE#1232, Updates `CFE_ES_FileWriteByteCntErr` to report status, not a `size_t` actual since `OS_write` returns `int32`. Use `int16` for local type from `CFE_TBL_FindTableInRegistry` since it's an index, not a status.
  nasa/cFE#1228, Replaces `<>` with `"` in local `#include`s
  nasa/cFE#1227, Adds `CONTRIBUING.md` that links to the main cFS contributing guide.

nasa/PSP#273 v1.5.0-rc1+dev90

  nasa/PSP#264, modular psp implementation
  nasa/PSP#272, Use quotes for local includes
  nasa/PSP#271, Add Contributing Guide

nasa/osal#917 v5.1.0-rc1+dev347

  nasa/osal#890, Move copyblock size to a #define and add comments
  nasa/osal#891, Removed rogue while loop
  nasa/osal#892, Scripted replacement for #include <os and #include <OSC_ matches of < and > with "
  nasa/osal#893, Consolidates the duplicated switch in OS_SocketOpen_Impl
  nasa/osal#894, Add `const` to input pointers
  nasa/osal#895, Removed network prototypes defined in osapi_sockets.h that are also in osapi_network.h
  nasa/osal#896, Removes NULL redefine from common_types.h
  nasa/osal#912, Add Contributing Guide
  nasa/osal#914, Utilize UTASSERT_CASETYPE_NA to report OS_ERR_NOT_IMPLEMENTED
  nasa/osal#898, correct interval calculation in DoSelect
  nasa/osal#909, comments describing select after connect
  nasa/osal#902, add check for EAGAIN in addition to EINTR
  nasa/osal#908, compile time assert for sockaddr size
  nasa/osal#910, check/report fcntl status
  nasa/osal#897, Add assert for FD_SET_SIZE in relation to OSAL_set
  nasa/osal#903, better error translation for ESPIPE errno
  nasa/osal#840, add shell functional test
  nasa/osal#901, rename OS_U32ValueWrapper_t
  nasa/osal#900, break up logic in return statement
  nasa/osal#906, return moduleInfoGet error
  nasa/osal#907, report timer_gettime error
  nasa/osal#899, remove unreachable test
  nasa/osal#905, make module comment same as other services
  nasa/osal#920 to fix test error check index inside fdset conversions
  nasa/osal#922, make non-selectable FD an error

nasa/sample_app#137 v1.2.0-rc1+dev54

  nasa/sample_app#134, Convert from <> to " for local includes
  nasa/sample_app#136, Added a contributing guide that links to the main cFS contributing guide.
  nasa/sample_app#132, Add context to the values for MsgIDs

nasa/sample_lib#55 v1.2.0-rc1+dev30

  nasa/sample_lib#54, Replace <> with " for local includes
  nasa/sample_lib#53, Adds CONTRIBUTING.md that links to the main cFS contributing guide.

nasa/cFS-GroundSystem#171 v2.2.0-rc1+dev41

  nasa/cFS-GroundSystem#166, Updated TBL and SB tlm for an operational TLM display
  nasa/cFS-GroundSystem#170, Add Contributing Guide
  nasa/cFS-GroundSystem#137, Create package for cfs-groundsystem
astrogeco added a commit to nasa/cFS that referenced this pull request Mar 22, 2021
nasa/cFE#1243 v6.8.0-rc1+dev436

  nasa/cFE#1225, Add coverage test fix
  nasa/cFE#1218, bit order macros
  nasa/cFE#1193, Removes incorrect statements from Application Developers Guide
  nasa/cFE#1235, Fixes truncation handling on vsnprintf error by adding a cast to avoid implicit conversion
  nasa/cFE#1220, Clarify the documentation on SB MsgId regarding requirements for command and telemetry messages
  nasa/cFE#1230, Cast isspace input to unsigned char to avoid undefined behavior
  nasa/cFE#1231, Updated message module, msgid v1 to use mask instead of cast to alter value
  nasa/cFE#1232, Coercion alters value caused by incorrect type - static analysis warning
  nasa/cFE#1228, Replaces `<>` with `"` in local `#include`s
  nasa/cFE#1227, Adds `CONTRIBUING.md` that links to the main cFS contributing guide.

nasa/PSP#273 v1.5.0-rc1+dev90

  nasa/PSP#264, modular psp implementation
  nasa/PSP#272, Use quotes for local includes
  nasa/PSP#271, Add Contributing Guide

nasa/osal#917 v5.1.0-rc1+dev347

  nasa/osal#890, Move copyblock size to a #define and add comments
  nasa/osal#891, Removed rogue while loop
  nasa/osal#892, Scripted replacement for #include <os and #include <OSC_ matches of < and > with "
  nasa/osal#893, Consolidates the duplicated switch in OS_SocketOpen_Impl
  nasa/osal#894, Add `const` to input pointers
  nasa/osal#895, Removed network prototypes defined in osapi_sockets.h that are also in osapi_network.h
  nasa/osal#896, Removes NULL redefine from common_types.h
  nasa/osal#912, Add Contributing Guide
  nasa/osal#914, Utilize UTASSERT_CASETYPE_NA to report OS_ERR_NOT_IMPLEMENTED
  nasa/osal#898, correct interval calculation in DoSelect
  nasa/osal#909, comments describing select after connect
  nasa/osal#902, add check for EAGAIN in addition to EINTR
  nasa/osal#908, compile time assert for sockaddr size
  nasa/osal#910, check/report fcntl status
  nasa/osal#897, Add assert for FD_SET_SIZE in relation to OSAL_set
  nasa/osal#903, better error translation for ESPIPE errno
  nasa/osal#840, add shell functional test
  nasa/osal#901, rename OS_U32ValueWrapper_t
  nasa/osal#900, break up logic in return statement
  nasa/osal#906, return moduleInfoGet error
  nasa/osal#907, report timer_gettime error
  nasa/osal#899, remove unreachable test
  nasa/osal#905, make module comment same as other services
  nasa/osal#920 to fix test error check index inside fdset conversions
  nasa/osal#922, make non-selectable FD an error

nasa/sample_app#137 v1.2.0-rc1+dev54

  nasa/sample_app#134, Convert from <> to " for local includes
  nasa/sample_app#136, Added a contributing guide that links to the main cFS contributing guide.
  nasa/sample_app#132, Add context to the values for MsgIDs

nasa/sample_lib#55 v1.2.0-rc1+dev30

  nasa/sample_lib#54, Replace <> with " for local includes
  nasa/sample_lib#53, Adds CONTRIBUTING.md that links to the main cFS contributing guide.

nasa/cFS-GroundSystem#171 v2.2.0-rc1+dev41

  nasa/cFS-GroundSystem#166, Updated TBL and SB tlm for an operational TLM display
  nasa/cFS-GroundSystem#170, Add Contributing Guide
  nasa/cFS-GroundSystem#137, Create package for cfs-groundsystem
@jphickey jphickey deleted the fix-861-sockaddr-size-check branch April 28, 2021 18:58
@skliper skliper added this to the 6.0.0 milestone Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use compile time assert on address length check in bind
3 participants