diff --git a/opal/mca/btl/tcp/btl_tcp_endpoint.c b/opal/mca/btl/tcp/btl_tcp_endpoint.c index c9dc90b5a4..012bb200e5 100644 --- a/opal/mca/btl/tcp/btl_tcp_endpoint.c +++ b/opal/mca/btl/tcp/btl_tcp_endpoint.c @@ -10,7 +10,7 @@ * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. * Copyright (c) 2007-2008 Sun Microsystems, Inc. All rights reserved. - * Copyright (c) 2013 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2013-2018 Cisco Systems, Inc. All rights reserved * Copyright (c) 2014 Intel, Inc. All rights reserved. * Copyright (c) 2015 Research Organization for Information Science * and Technology (RIST). All rights reserved. @@ -56,6 +56,7 @@ #include "opal/util/show_help.h" #include "opal/util/proc.h" #include "opal/util/printf.h" +#include "opal/util/string_copy.h" #include "opal/mca/btl/base/btl_base_error.h" #include "btl_tcp.h" @@ -404,7 +405,8 @@ mca_btl_tcp_endpoint_send_connect_ack(mca_btl_base_endpoint_t* btl_endpoint) OPAL_PROCESS_NAME_HTON(guid); mca_btl_tcp_endpoint_hs_msg_t hs_msg; - strcpy(hs_msg.magic_id, mca_btl_tcp_magic_id_string); + opal_string_copy(hs_msg.magic_id, mca_btl_tcp_magic_id_string, + sizeof(hs_msg.magic_id)); hs_msg.guid = guid; if(sizeof(hs_msg) != diff --git a/opal/test/reachable/reachable_netlink.c b/opal/test/reachable/reachable_netlink.c index 3fdedbf84e..ea270f339c 100644 --- a/opal/test/reachable/reachable_netlink.c +++ b/opal/test/reachable/reachable_netlink.c @@ -1,6 +1,7 @@ /* * Copyright (c) 2017 Amazon.com, Inc. or its affiliates. All Rights * reserved. + * Copyright (c) 2018 Cisco Systems, Inc. All rights reserved * $COPYRIGHT$ * * Additional copyrights may follow @@ -137,7 +138,7 @@ int main(int argc, char **argv) break; default: family = "Unknown"; - strcpy(addr, "Unknown"); + opal_string_copy(addr, "Unknown", sizeof(addr)); break; } @@ -165,7 +166,7 @@ int main(int argc, char **argv) break; default: family = "Unknown"; - strcpy(addr, "Unknown"); + opal_string_copy(addr, "Unknown", sizeof(addr)); break; } diff --git a/opal/util/opal_pty.c b/opal/util/opal_pty.c index 014eacb8c7..9c70ecc668 100644 --- a/opal/util/opal_pty.c +++ b/opal/util/opal_pty.c @@ -9,6 +9,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2018 Cisco Systems, Inc. All rights reserved * $COPYRIGHT$ * * Additional copyrights may follow @@ -135,7 +136,9 @@ int opal_openpty(int *amaster, int *aslave, char *name, return -1; } if (name) { - strcpy(name, line); + // We don't know the max length of name, but we do know the + // max length of the source, so at least use that. + opal_string_copy(name, line, sizeof(line)); } #ifndef TCSAFLUSH #define TCSAFLUSH TCSETAF diff --git a/opal/util/os_path.c b/opal/util/os_path.c index ad8792c015..5a29e9767c 100644 --- a/opal/util/os_path.c +++ b/opal/util/os_path.c @@ -54,14 +54,12 @@ char *opal_os_path(int relative, ...) va_end(ap); if (0 == num_elements) { /* must be looking for a simple answer */ - path = (char *)malloc(3); - path[0] = '\0'; + size_t len = 3; + path = (char *)calloc(len, sizeof(char)); if (relative) { - strcpy(path, "."); - strcat(path, path_sep); - } else { - strcpy(path, path_sep); - } + path[0] = '.'; + } + strncat(path, path_sep, len); return(path); } @@ -76,28 +74,27 @@ char *opal_os_path(int relative, ...) return(NULL); } - path = (char *)malloc(total_length); + path = (char *)calloc(total_length, sizeof(char)); if (NULL == path) { return(NULL); } - path[0] = 0; if (relative) { - strcpy(path, "."); + path[0] = '.'; } va_start(ap, relative); if( NULL != (element = va_arg(ap, char*)) ) { if (path_sep[0] != element[0]) { - strcat(path, path_sep); + strncat(path, path_sep, total_length); } strcat(path, element); } while (NULL != (element=va_arg(ap, char*))) { if (path_sep[0] != element[0]) { - strcat(path, path_sep); + strncat(path, path_sep, total_length); } - strcat(path, element); + strncat(path, element, total_length); } va_end(ap); diff --git a/opal/util/path.c b/opal/util/path.c index 7c69c017ce..d49a046685 100644 --- a/opal/util/path.c +++ b/opal/util/path.c @@ -9,7 +9,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. - * Copyright (c) 2009-2014 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2009-2018 Cisco Systems, Inc. All rights reserved * Copyright (c) 2010 IBM Corporation. All rights reserved. * Copyright (c) 2012-2013 Los Alamos National Security, LLC. * All rights reserved. @@ -77,6 +77,7 @@ #include "opal/util/path.h" #include "opal/util/os_path.h" #include "opal/util/argv.h" +#include "opal/util/printf.h" /* * Sanity check to ensure we have either statfs or statvfs @@ -146,12 +147,7 @@ char *opal_path_find(char *fname, char **pathv, int mode, char **envv) if (!delimit) { fullpath = opal_path_access(fname, env, mode); } else { - pfix = (char*) malloc(strlen(env) + strlen(delimit) + 1); - if (NULL == pfix) { - return NULL; - } - strcpy(pfix, env); - strcat(pfix, delimit); + opal_asprintf(&pfix, "%s%s", env, delimit); fullpath = opal_path_access(fname, pfix, mode); free(pfix); }