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
lib/posix-sysinfo: Fix off-by-1 error in sethostname
#1307
Conversation
This change adds declarations of gethostname and sethostname to nolibc's unistd.h when CONFIG_LIBPOSIX_SYSINFO is enabled. Additionally, the sysinfo declarations are moved after shared includes. Signed-off-by: Andrei Tatar <andrei@unikraft.io>
This change fixes an off-by-1 error in sethostname when checking the length of the new hostname, leading to a missing terminating NUL byte in the `nodename` field of `struct utsname`, contrary to the expected Linux ABI. Additionally, strncpy is replaced with a more appropriate memcpy call. Signed-off-by: Andrei Tatar <andrei@unikraft.io>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, however, please fix the NUL
typo in commit's c704be7 message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from what @mariasfiraiala stated here, looks good.
Reviewed-by: Adina-Maria Vaman adinamariav22@gmail.com
@mariasfiraiala Oh that's on purpose, I meant that as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed-by: Maria Sfiraiala maria.sfiraiala@gmail.com
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved-by: Razvan Deaconescu razvand@unikraft.io
This change adds declarations of gethostname and sethostname to nolibc's unistd.h when CONFIG_LIBPOSIX_SYSINFO is enabled. Additionally, the sysinfo declarations are moved after shared includes. Signed-off-by: Andrei Tatar <andrei@unikraft.io> Reviewed-by: Maria Sfiraiala <maria.sfiraiala@gmail.com> Approved-by: Razvan Deaconescu <razvand@unikraft.io> GitHub-Closes: #1307
This change fixes an off-by-1 error in sethostname when checking the length of the new hostname, leading to a missing terminating NUL byte in the `nodename` field of `struct utsname`, contrary to the expected Linux ABI. Additionally, strncpy is replaced with a more appropriate memcpy call. Signed-off-by: Andrei Tatar <andrei@unikraft.io> Reviewed-by: Maria Sfiraiala <maria.sfiraiala@gmail.com> Approved-by: Razvan Deaconescu <razvand@unikraft.io> GitHub-Closes: #1307
Description of changes
This change corrects an an off-by-1 error in sethostname when checking the length of the new hostname, leading to a missing terminating NUL byte in the
nodename
field ofstruct utsname
, contrary to the expected Linux ABI. The suboptimalstrncpy
call is also replaced with a more appropriatememcpy
call, since (1) we know the length of the input string, which (2) does not need to be NUL-terminated.Additionally, declarations of
gethostname
andsethostname
are added tonolibc
'sunistd.h
, making these functions available to core unikraft as well as microlibraries.Prerequisite checklist
checkpatch.uk
on your commit series before opening this PR;Base target
Additional configuration
CONFIG_LIBPOSIX_SYSINFO=y
Test snippet:
On
staging
it incorrectly sets a hostname without a NUL byte, resulting in the Unikraft version leaking into the hostname:After the fix, it should correctly error out of the first
sethostname
call: