|
13 | 13 | * All rights reserved. |
14 | 14 | * Copyright (c) 2015 Research Organization for Information Science |
15 | 15 | * and Technology (RIST). All rights reserved. |
16 | | - * Copyright (c) 2015 Cisco Systems, Inc. All rights reserved. |
| 16 | + * Copyright (c) 2015-2018 Cisco Systems, Inc. All rights reserved |
17 | 17 | * $COPYRIGHT$ |
18 | 18 | * |
19 | 19 | * Additional copyrights may follow |
@@ -110,26 +110,28 @@ int MPI_Comm_join(int fd, MPI_Comm *intercomm) |
110 | 110 | send_first = true; |
111 | 111 | } |
112 | 112 |
|
113 | | - /* ensure the port name is NULL terminated */ |
114 | | - memset(port_name, 0, MPI_MAX_PORT_NAME); |
115 | | - |
116 | 113 | /* Assumption: socket_send should not block, even if the socket |
117 | 114 | is not configured to be non-blocking, because the message length are |
118 | 115 | so short. */ |
119 | 116 |
|
120 | 117 | /* we will only use the send_first proc's port name, |
121 | 118 | * so pass it to the recv_first participant */ |
122 | 119 | if (send_first) { |
123 | | - /* open a port */ |
| 120 | + // The port_name that we get back will be \0-terminated. The |
| 121 | + // strlen+\0 will be <= MPI_MAX_PORT_NAME characters. |
124 | 122 | if (OMPI_SUCCESS != (rc = ompi_dpm_open_port(port_name))) { |
125 | 123 | goto error; |
126 | 124 | } |
| 125 | + // Send the strlen+1 so that we both send the \0 and the |
| 126 | + // receiver receives the \0. |
127 | 127 | llen = (uint32_t)(strlen(port_name)+1); |
128 | 128 | len = htonl(llen); |
129 | 129 | ompi_socket_send( fd, (char *) &len, sizeof(uint32_t)); |
130 | 130 | ompi_socket_send (fd, port_name, llen); |
131 | 131 | } else { |
132 | 132 | ompi_socket_recv (fd, (char *) &rlen, sizeof(uint32_t)); |
| 133 | + // The lrlen that we receive will be the strlen+1 (to account |
| 134 | + // for \0), and will be <= MPI_MAX_PORT_NAME. |
133 | 135 | lrlen = ntohl(rlen); |
134 | 136 | ompi_socket_recv (fd, port_name, lrlen); |
135 | 137 | } |
|
0 commit comments