From c75c0eb6a5e207307399b5f4fa88b8d8ac4c737a Mon Sep 17 00:00:00 2001 From: "Mark F. Brown" Date: Thu, 5 Dec 2024 18:13:51 -0500 Subject: [PATCH] Fixed Off-by-one error in gethostname() 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 --- src/runtime_util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runtime_util.c b/src/runtime_util.c index 3ce0c5ba7..bd9ccc992 100644 --- a/src/runtime_util.c +++ b/src/runtime_util.c @@ -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; @@ -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;