Fix wrong struct layout in getInterfaceSpeedGLinkSettings #382
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
SIOCETHTOOL
IOCTL expects a pointer to an instance ofethtool_link_settings
.E.g. it will read the
cmd
member to determine what to do. However #346 reordered the memory layout of the pointer such that actually and array of__32
values (zeroed out) is passed. Hence the IOCTL will either fail because an invalid command (cmd=0
) is passed or the values read later by e.g.ecmd.req.link_mode_masks_nwords
are something completely different.So
ethtool_link_settings
has to come before the (stack) memory used in the flexible array at the end of this struct.To avoid GCC warnigns/errors (see #345) an union is used that provides the current struct (i.e. with wrong order) and an access the actually used
struct ethtool_link_settings
at the top.Alternative approach to #348 likely avoiding any undefined behavior (union based type punning is usually supported by compilers, so this should work to get the required memory)