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 Sandia-OpenSHMEM#1159

Signed-off-by: Mark F. Brown <[email protected]>
  • Loading branch information
markbrown314 committed Dec 6, 2024
1 parent 45e6e7e commit c75c0eb
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -123,7 +123,7 @@ int shmem_runtime_util_populate_node(int *location_array, int size, int *node_si
int ret, i, n_node_pes = 0;
char hostname[MAX_HOSTNAME_LEN+1];

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 c75c0eb

Please sign in to comment.