Ensure that sethostname null terminates the hostname correctly#5107
Merged
Conversation
xiaoxiang781216
approved these changes
Dec 29, 2021
Contributor
|
Let's squash the patch into one |
jerpelea
approved these changes
Dec 29, 2021
commit e1c306f added sethostname using strncpy. This replaces it with strlcpy and uses sizeof() instead of re-calculating the buffer size. Rename size argument for get/sethostname to match the implementation
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.
Summary
commit e1c306f added sethostname. The null terminator should be added after the new hostname (and only at the very end if the new hostname is the maximum length).
Impact
Without this if the hostname is set to
hello-worldand then it's set toshort, the resulting hostname is incorrectlyshort-world.Also renamed the
sizeargument (forsethostnamecode and forgethostnameandsethostnamein the header file) tonamelento match thegethostnamecode and the blockcomment input parameter names.Testing
Manually tested with medium and then short hostnames. Also tested with hostnames 31, 32, and 33 characters in length to check that they were truncated correctly.