Skip to content

Commit

Permalink
Fixed Off-by-one error in gethostname()
Browse files Browse the repository at this point in the history
MAX_HOSTNAME_LEN is the maximum total characters of the hostname not
including the end of string character '\0'. If the hostname happens to
be 64 characters long, gethostname() would return an error and
shmem_runtime_util_put_hostname() would state error "gethostname failed
(-1)"

Changed length to MAX_HOSTNAME_LEN+1

Issue #1159

Signed-off-by: Mark F. Brown <[email protected]>
  • Loading branch information
markbrown314 committed Dec 5, 2024
1 parent 45e6e7e commit 7bc5df6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/runtime_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ int shmem_runtime_util_put_hostname(void)
char hostname[MAX_HOSTNAME_LEN+1];
int ret;

ret = gethostname(hostname, MAX_HOSTNAME_LEN);
ret = gethostname(hostname, MAX_HOSTNAME_LEN+1);
if (ret != 0) {
RETURN_ERROR_MSG("gethostname failed (%d)", ret);
return ret;
Expand Down

0 comments on commit 7bc5df6

Please sign in to comment.