Fix errors due to bad strncpy behavour. #1193
Merged
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.
As of GCC 8.1 a compiler error (stringop-truncation) will be raised as
strncpy
has potentially unsafe behavour, which I think is the case here (not sure if there is a limiting factor onpath
's length?)If
strncpy
's source (path in our case) is longer than the destination the destination will not be null terminated. Which is whatsockaddr_un
requires ofsockaddr_un.sun_path
, from the man page unix(7):and
By reducing the copy size by one ensures as much as path as can be copied is and pads the rest of destination (the remaining one character) with null bytes, ensuring it's properly null terminated. See man page strcpy(3) for it's behavour: