Skip to content
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

Off-by-one error for gethostname() in runtime code #1159

Open
markbrown314 opened this issue Dec 5, 2024 · 0 comments
Open

Off-by-one error for gethostname() in runtime code #1159

markbrown314 opened this issue Dec 5, 2024 · 0 comments

Comments

@markbrown314
Copy link
Collaborator

src/runtime_util.c: shmem_runtime_util_put_hostname() calls gethostname() with a length of MAX_HOSTNAME_LEN (which resolves to 64 bytes in Linux).

    ret = gethostname(hostname, MAX_HOSTNAME_LEN);
    if (ret != 0) {
        RETURN_ERROR_MSG("gethostname failed (%d)", ret);
        return ret;
    }

The issue is 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)"

The input length parameter needs to be set to MAX_HOSTNAME_LEN+1

markbrown314 added a commit to markbrown314/SOS that referenced this issue Dec 5, 2024
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]>
markbrown314 added a commit to markbrown314/SOS that referenced this issue Dec 6, 2024
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant