1
1
Enusre that the port name is always NULL-terminated.

Signed-off-by: Jeff Squyres <jsquyres@cisco.com>
Этот коммит содержится в:
Jeff Squyres 2018-03-24 05:54:40 -07:00
родитель 6319292170
Коммит dca66b9775
2 изменённых файлов: 9 добавлений и 6 удалений

Просмотреть файл

@ -10,7 +10,7 @@
* University of Stuttgart. All rights reserved. * University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California. * Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved. * All rights reserved.
* Copyright (c) 2007-2015 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2007-2018 Cisco Systems, Inc. All rights reserved
* Copyright (c) 2006-2009 University of Houston. All rights reserved. * Copyright (c) 2006-2009 University of Houston. All rights reserved.
* Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved. * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
* Copyright (c) 2011-2015 Los Alamos National Security, LLC. All rights * Copyright (c) 2011-2015 Los Alamos National Security, LLC. All rights
@ -958,6 +958,7 @@ int ompi_dpm_open_port(char *port_name)
r = opal_rand(&rnd); r = opal_rand(&rnd);
opal_convert_process_name_to_string(&tmp, OMPI_PROC_MY_NAME); opal_convert_process_name_to_string(&tmp, OMPI_PROC_MY_NAME);
snprintf(port_name, MPI_MAX_PORT_NAME-1, "%s:%u", tmp, r); snprintf(port_name, MPI_MAX_PORT_NAME-1, "%s:%u", tmp, r);
port_name[MPI_MAX_PORT_NAME - 1] = '\0';
free(tmp); free(tmp);
return OMPI_SUCCESS; return OMPI_SUCCESS;
} }

Просмотреть файл

@ -13,7 +13,7 @@
* All rights reserved. * All rights reserved.
* Copyright (c) 2015 Research Organization for Information Science * Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved. * and Technology (RIST). All rights reserved.
* Copyright (c) 2015 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2015-2018 Cisco Systems, Inc. All rights reserved
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -110,9 +110,6 @@ int MPI_Comm_join(int fd, MPI_Comm *intercomm)
send_first = true; send_first = true;
} }
/* ensure the port name is NULL terminated */
memset(port_name, 0, MPI_MAX_PORT_NAME);
/* Assumption: socket_send should not block, even if the socket /* Assumption: socket_send should not block, even if the socket
is not configured to be non-blocking, because the message length are is not configured to be non-blocking, because the message length are
so short. */ so short. */
@ -120,16 +117,21 @@ int MPI_Comm_join(int fd, MPI_Comm *intercomm)
/* we will only use the send_first proc's port name, /* we will only use the send_first proc's port name,
* so pass it to the recv_first participant */ * so pass it to the recv_first participant */
if (send_first) { if (send_first) {
/* open a port */ // The port_name that we get back will be \0-terminated. The
// strlen+\0 will be <= MPI_MAX_PORT_NAME characters.
if (OMPI_SUCCESS != (rc = ompi_dpm_open_port(port_name))) { if (OMPI_SUCCESS != (rc = ompi_dpm_open_port(port_name))) {
goto error; goto error;
} }
// Send the strlen+1 so that we both send the \0 and the
// receiver receives the \0.
llen = (uint32_t)(strlen(port_name)+1); llen = (uint32_t)(strlen(port_name)+1);
len = htonl(llen); len = htonl(llen);
ompi_socket_send( fd, (char *) &len, sizeof(uint32_t)); ompi_socket_send( fd, (char *) &len, sizeof(uint32_t));
ompi_socket_send (fd, port_name, llen); ompi_socket_send (fd, port_name, llen);
} else { } else {
ompi_socket_recv (fd, (char *) &rlen, sizeof(uint32_t)); ompi_socket_recv (fd, (char *) &rlen, sizeof(uint32_t));
// The lrlen that we receive will be the strlen+1 (to account
// for \0), and will be <= MPI_MAX_PORT_NAME.
lrlen = ntohl(rlen); lrlen = ntohl(rlen);
ompi_socket_recv (fd, port_name, lrlen); ompi_socket_recv (fd, port_name, lrlen);
} }