Skip to content

Commit 470452c

Browse files
author
Ralph Castain
committed
Correctly check the sa_family and cast the data correctly before passing it to inet_nop, and don't be quite as fancy with the pointer arithmetic as the combination was causing us to segfault every time this debug message was called.
Signed-off-by: Ralph Castain <[email protected]>
1 parent 0694d0b commit 470452c

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

opal/mca/btl/tcp/btl_tcp_proc.c

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Copyright (c) 2004-2005 The Regents of the University of California.
1212
* All rights reserved.
1313
* Copyright (c) 2008-2010 Oracle and/or its affiliates. All rights reserved
14-
* Copyright (c) 2013-2015 Intel, Inc. All rights reserved
14+
* Copyright (c) 2013-2017 Intel, Inc. All rights reserved.
1515
* Copyright (c) 2014-2016 Research Organization for Information Science
1616
* and Technology (RIST). All rights reserved.
1717
* Copyright (c) 2015-2016 Los Alamos National Security, LLC. All rights
@@ -828,33 +828,38 @@ void mca_btl_tcp_proc_accept(mca_btl_tcp_proc_t* btl_proc, struct sockaddr* addr
828828
/* No further use of this socket. Close it */
829829
CLOSE_THE_SOCKET(sd);
830830
{
831-
size_t len = 1024;
832-
char* addr_str = (char*)malloc(len);
833-
if( NULL != addr_str ) {
834-
memset(addr_str, 0, len);
835-
for (size_t i = 0; i < btl_proc->proc_endpoint_count; i++) {
836-
mca_btl_base_endpoint_t* btl_endpoint = btl_proc->proc_endpoints[i];
837-
if (btl_endpoint->endpoint_addr->addr_family != addr->sa_family) {
838-
continue;
839-
}
840-
841-
if (addr_str[0] != '\0') {
842-
strncat(addr_str, ", ", len);
843-
len -= 2;
844-
}
845-
strncat(addr_str, inet_ntop(AF_INET6, (void*)(struct in6_addr*)&btl_endpoint->endpoint_addr->addr_inet,
846-
addr_str + 1024 - len, INET6_ADDRSTRLEN), len);
847-
len = 1024 - strlen(addr_str);
831+
char *addr_str=NULL, *tmp, pnet[1024];
832+
for (size_t i = 0; i < btl_proc->proc_endpoint_count; i++) {
833+
mca_btl_base_endpoint_t* btl_endpoint = btl_proc->proc_endpoints[i];
834+
if (btl_endpoint->endpoint_addr->addr_family != addr->sa_family) {
835+
continue;
848836
}
837+
if (AF_INET == addr->sa_family) {
838+
inet_ntop(AF_INET, (void*)(struct in_addr*)&btl_endpoint->endpoint_addr->addr_inet, pnet, 1024);
839+
} else if (AF_INET6 == addr->sa_family) {
840+
inet_ntop(AF_INET6, (void*)(struct in6_addr*)&btl_endpoint->endpoint_addr->addr_inet, pnet, 1024);
841+
} else {
842+
/* unrecognized family */
843+
continue;
844+
}
845+
if (NULL == addr_str) {
846+
(void)asprintf(&tmp, "\n\t%s", pnet);
847+
} else {
848+
(void)asprintf(&tmp, "%s\n\t%s", addr_str, pnet);
849+
free(addr_str);
850+
}
851+
addr_str = tmp;
849852
}
850853
opal_show_help("help-mpi-btl-tcp.txt", "dropped inbound connection",
851854
true, opal_process_info.nodename,
852855
getpid(),
853856
btl_proc->proc_opal->proc_hostname,
854857
OPAL_NAME_PRINT(btl_proc->proc_opal->proc_name),
855858
opal_net_get_hostname((struct sockaddr*)addr),
856-
addr_str);
857-
free(addr_str);
859+
(NULL == addr_str) ? "NONE" : addr_str);
860+
if (NULL != addr_str) {
861+
free(addr_str);
862+
}
858863
}
859864
OPAL_THREAD_UNLOCK(&btl_proc->proc_lock);
860865
}

0 commit comments

Comments
 (0)