Repository navigation
fix strlcpy len computation in netmap_bdg.c - #991
Merged
Merged
Conversation
An instance of strncpy() was converted to strlcpy() without modifying the length parameter. strlcpy() will only copy up to len - 1 bytes so the final byte was being dropped. Now use the size of the destination buffer as the length then set '\0' at the appropriate offset.
Collaborator
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In the recent commit cd23e3a, a call of
strncpy(b->bdg_basename, name, namelen)was changed tostrlcpy(b->bdg_basename, name, namelen).strncpy()will copy up tonamelenbytes whilestrlcpy()will only copy to upnamelen - 1bytes.strlcpy()should typically be given the size of the destination buffer, not the number of characters in the source. But in this case, the goal is to truncate thenamestring before the colon ':' character.I am proposing a two step solution. First
strlcpy()is used with the length of the destination buffer to ensure there are no buffer overflows. Second, a '\0' is placed at thenamelenposition to terminate the name.