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 shmem_perf common code #48

Open
markbrown314 opened this issue Dec 9, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@markbrown314
Copy link
Collaborator

test/performance/shmem_perf_suite/common.h:check_hostname_validation()

    int hostname_size = MAX_HOSTNAME_LEN;
    int i, errors = 0;

    char *hostname = (char *) shmem_malloc (hostname_size * sizeof(char));
    char *dest = (char *) shmem_malloc (my_info->num_pes * hostname_size *
                                        sizeof(char));

    if (hostname == NULL || dest == NULL) {
        fprintf(stderr, "shmem_malloc failed to allocate for hostname strings\n");
        return -1;
    }

    hostname_status = gethostname(hostname, hostname_size);
    if (hostname_status != 0) {
        fprintf(stderr, "gethostname failed (%d)\n", hostname_status);
        return -1;
    }

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 markbrown314 added the bug Something isn't working label Dec 9, 2024
markbrown314 added a commit to markbrown314/tests-sos that referenced this issue Dec 9, 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 openshmem-org#48

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
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants