Skip to content

Conversation

@jsquyres
Copy link
Member

@jsquyres jsquyres commented Sep 26, 2018

EDIT: This PR completely changed after it was created. It was initially just fixing a single compiler warning. It grew into replacing all strcpy() and strncpy() instances with calls to a new function: opal_string_copy().


Original description

memset() the string, assert() to make sure it's long enough, and also
use strncat() (which is guaranteed to \0-terminate the string).

Signed-off-by: Jeff Squyres jsquyres@cisco.com

Follow on to #5779 (review)

@rhc54
Copy link
Contributor

rhc54 commented Sep 26, 2018

Are we going to do this everywhere? Otherwise, why does this particular code snippet deserve such treatment? Not saying it is bad - just asking why here and not everywhere.

@bwbarrett
Copy link
Member

Jeff asked if I'd review the release branch PRs for #5779. I pointed out his fix wasn't safe, so this is the follow up in master to make the fixes actually be safe.

@rhc54
Copy link
Contributor

rhc54 commented Sep 26, 2018

I get that - my point was that this same code exists all over the code base, not just in this one place. So if we are going to fix it here, then shouldn't it really go everywhere?

In which case, why not put it in an opal_strncpy function so we don't copy these gyrations a hundred times?

@bwbarrett
Copy link
Member

I assume Jeff's going to fix all the compiler warnings. I'm only asking that he fix them correctly :).

I'm not really happy with this patch. I'd much prefer the explicit set to '\0' rather than the implicit assumption the memset occurs earlier. It's hard to enforce that assumption, easy to explicitly set, and this code isn't in the performance critical path.

@jsquyres
Copy link
Member Author

Per the commit message, strncat() guarantees to NULL-terminate; that's why I switched it it (vs. strncpy()). See http://www.cplusplus.com/reference/cstring/strncat/.

FWIW, I was fixing compiler warnings. Other places didn't trip up compiler warnings... If it's not too onerous, I can fix up other places. Can you cite some of them?

@rhc54
Copy link
Contributor

rhc54 commented Sep 26, 2018

Here it is for strcpy:

contrib/ompi-time.sh
380:        strcpy(name, "localhost");

examples/connectivity_c.c
38:        strcpy(name, "unknown");

ompi/mca/common/ompio/common_ompio_file_open.c
246:        strcpy (name, "WRITE");
256:        strcpy (name, "READ");

ompi/mca/io/ompio/io_ompio_file_set_view.c
98:    strcpy (datarep, fh->f_datarep);

ompi/mca/io/romio321/romio/adio/common/strfns.c
44:    Thus, this routine may be used anywhere 'strcpy' is used, without any

ompi/mca/io/romio321/romio/confdb/ltmain.sh
5840:  strcpy (newargz[0], actual_cwrapper_path);
5941:  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
6073:		  strcpy (concat_name + tmp_len + 1, wrapper);
6081:		  strcpy (concat_name + p_len + 1, wrapper);
6098:  strcpy (concat_name + tmp_len + 1, wrapper);
6266:          strcpy (new_value, orig_value);
6267:          strcpy (new_value + orig_value_len, add);
6271:          strcpy (new_value, add);
6272:          strcpy (new_value + add_len, orig_value);

ompi/mca/io/romio321/romio/test-internal/heap_test.c
124:	strcpy(test.name, "RANDOMIZED TEST");
127:	strcpy(test.name, "CUSTOM TEST");
341:	    strcpy(params->name, "TEST 1");
399:	    strcpy(params->name, "TEST 1");

ompi/mca/io/romio321/romio/test/.codingcheck
5:	'strcpy' => sys, 'strncpy' => sys, 'strcat' => sys, 

ompi/mca/io/romio321/romio/test/async-multiple.c
57:	strcpy(filename, *argv);
74:    strcpy(tmp, filename);

ompi/mca/io/romio321/romio/test/async.c
55:	strcpy(filename, *argv);
72:    strcpy(tmp, filename);

ompi/mca/io/romio321/romio/test/atomicity.c
48:	strcpy(filename, *argv);

ompi/mca/io/romio321/romio/test/coll_perf.c
53:	strcpy(filename, *argv);

ompi/mca/io/romio321/romio/test/coll_test.c
67:	strcpy(filename, *argv);

ompi/mca/io/romio321/romio/test/creat_excl.c
40:				strcpy(opts->fname, argv[i+1]);

ompi/mca/io/romio321/romio/test/error.c
47:	strcpy(filename, *argv);
59:    strcpy(tmp, filename);

ompi/mca/io/romio321/romio/test/excl.c
38:        strcpy(filename, *argv);

ompi/mca/io/romio321/romio/test/file_info.c
97:	strcpy(filename, *argv);

ompi/mca/io/romio321/romio/test/i_noncontig.c
52:	strcpy(filename, *argv);

ompi/mca/io/romio321/romio/test/large_array.c
52:	strcpy(filename, *argv);

ompi/mca/io/romio321/romio/test/large_file.c.in
51:    strcpy(filename, *argv);

ompi/mca/io/romio321/romio/test/misc.c.in
53:	strcpy(filename, *argv);

ompi/mca/io/romio321/romio/test/noncontig.c
51:	strcpy(filename, *argv);

ompi/mca/io/romio321/romio/test/noncontig_coll.c
50:	strcpy(filename, *argv);

ompi/mca/io/romio321/romio/test/noncontig_coll2.c
283:	strcpy(filename, *argv);

ompi/mca/io/romio321/romio/test/ordered_fp.c
57:	strcpy(filename, *argv);

ompi/mca/io/romio321/romio/test/perf.c
44:	strcpy(filename, *argv);

ompi/mca/io/romio321/romio/test/psimple.c
46:	strcpy(filename, *argv);
63:    strcpy(tmp, filename);

ompi/mca/io/romio321/romio/test/shared_fp.c
52:	strcpy(filename, *argv);

ompi/mca/io/romio321/romio/test/simple.c
51:	strcpy(filename, *argv);
68:    strcpy(tmp, filename);

ompi/mca/io/romio321/romio/test/split_coll.c
54:	strcpy(filename, *argv);

ompi/mca/io/romio321/romio/test/status.c
41:	strcpy(filename, *argv);
56:    strcpy(tmp, filename);

ompi/mca/io/romio321/romio/test/misc.c
53:	strcpy(filename, *argv);

ompi/mca/io/romio321/romio/test/large_file.c
51:    strcpy(filename, *argv);

ompi/mca/io/romio321/romio/libtool
6352:  strcpy (newargz[0], actual_cwrapper_path);
6453:  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
6585:		  strcpy (concat_name + tmp_len + 1, wrapper);
6593:		  strcpy (concat_name + p_len + 1, wrapper);
6610:  strcpy (concat_name + tmp_len + 1, wrapper);
6778:          strcpy (new_value, orig_value);
6779:          strcpy (new_value + orig_value_len, add);
6783:          strcpy (new_value, add);
6784:          strcpy (new_value + add_len, orig_value);

ompi/mpi/tool/cvar_read.c
82:                strcpy ((char *) buf, value->stringval);

opal/mca/btl/tcp/btl_tcp_endpoint.c
405:    strcpy(hs_msg.magic_id, mca_btl_tcp_magic_id_string);

opal/mca/btl/uct/btl_uct_component.c
166:    strcpy ((char *) modex_data, tl->uct_tl_name);
211:        strcpy ((char *) modex_data, module->md_name);

opal/mca/event/libevent2022/libevent/ChangeLog
771: o Replace (safe) use of strcpy with memcpy to appease OpenBSD (caca2f4)

opal/mca/event/libevent2022/libevent/test/regress_main.c
128:	strcpy(tmpfilename, "/tmp/eventtmp.XXXXXX");

opal/mca/event/libevent2022/libevent/ltmain.sh
5840:  strcpy (newargz[0], actual_cwrapper_path);
5941:  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
6073:		  strcpy (concat_name + tmp_len + 1, wrapper);
6081:		  strcpy (concat_name + p_len + 1, wrapper);
6098:  strcpy (concat_name + tmp_len + 1, wrapper);
6266:          strcpy (new_value, orig_value);
6267:          strcpy (new_value + orig_value_len, add);
6271:          strcpy (new_value, add);
6272:          strcpy (new_value + add_len, orig_value);

opal/mca/event/libevent2022/libevent/libtool
6338:  strcpy (newargz[0], actual_cwrapper_path);
6439:  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
6571:		  strcpy (concat_name + tmp_len + 1, wrapper);
6579:		  strcpy (concat_name + p_len + 1, wrapper);
6596:  strcpy (concat_name + tmp_len + 1, wrapper);
6764:          strcpy (new_value, orig_value);
6765:          strcpy (new_value + orig_value_len, add);
6769:          strcpy (new_value, add);
6770:          strcpy (new_value + add_len, orig_value);

opal/mca/hwloc/hwloc201/hwloc/hwloc/topology-linux.c
2522:  strcpy(path+pathlen, dmi_name);
2542:  strcpy(path, "/sys/devices/virtual/dmi/id");
2547:    strcpy(path, "/sys/class/dmi/id");
3085:    strcpy(hwdata->memory_mode, "Cache");
3088:      strcpy(hwdata->memory_mode, "Flat");
3090:      strcpy(hwdata->memory_mode, "Hybrid50");
3092:      strcpy(hwdata->memory_mode, "Hybrid25");
3097:    strcpy(hwdata->cluster_mode, "SNC4");
3099:    strcpy(hwdata->cluster_mode, "SNC2");
4963:      strcpy(blocktype, "NVDIMM"); /* Save the blocktype now since udev reports "" so far */
5057:      strcpy(vendor, "Western Digital");
5059:      strcpy(vendor, "Seagate");
5061:      strcpy(vendor, "Samsung");
5063:      strcpy(vendor, "SanDisk");
5065:      strcpy(vendor, "Toshiba");

opal/mca/hwloc/hwloc201/hwloc/hwloc/topology-xml-nolibxml.c
577:    case '\n': strcpy(dst, "
");  replen=5; break;
578:    case '\r': strcpy(dst, "
");  replen=5; break;
579:    case '\t': strcpy(dst, "	");   replen=4; break;
580:    case '\"': strcpy(dst, """); replen=6; break;
581:    case '<':  strcpy(dst, "&lt;");   replen=4; break;
582:    case '>':  strcpy(dst, "&gt;");   replen=4; break;
583:    case '&':  strcpy(dst, "&amp;");  replen=5; break;

opal/mca/pmix/base/pmix_base_fns.c
458:        strcpy (tmp_encoded + bytes_read, pmi_tmp);

opal/mca/pmix/pmix4x/pmix/config/ltmain.sh.orig
5840:  strcpy (newargz[0], actual_cwrapper_path);
5941:  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
6073:		  strcpy (concat_name + tmp_len + 1, wrapper);
6081:		  strcpy (concat_name + p_len + 1, wrapper);
6098:  strcpy (concat_name + tmp_len + 1, wrapper);
6266:          strcpy (new_value, orig_value);
6267:          strcpy (new_value + orig_value_len, add);
6271:          strcpy (new_value, add);
6272:          strcpy (new_value + add_len, orig_value);

opal/mca/pmix/pmix4x/pmix/config/ltmain.sh
5840:  strcpy (newargz[0], actual_cwrapper_path);
5941:  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
6073:		  strcpy (concat_name + tmp_len + 1, wrapper);
6081:		  strcpy (concat_name + p_len + 1, wrapper);
6098:  strcpy (concat_name + tmp_len + 1, wrapper);
6266:          strcpy (new_value, orig_value);
6267:          strcpy (new_value + orig_value_len, add);
6271:          strcpy (new_value, add);
6272:          strcpy (new_value + add_len, orig_value);

opal/mca/pmix/pmix4x/pmix/src/common/pmix_strings.c
247:        strcpy(&answer[cnt], "STDIN ");
251:        strcpy(&answer[cnt], "STDOUT ");
255:        strcpy(&answer[cnt], "STDERR ");
259:        strcpy(&answer[cnt], "STDDIAG ");
263:        strcpy(&answer[cnt], "NONE");

opal/mca/pmix/pmix4x/pmix/src/mca/preg/native/preg_native.c
934:        strcpy(str, base);

opal/mca/pmix/pmix4x/pmix/src/util/os_path.c
61:            strcpy(path, ".");
64:            strcpy(path, path_sep);
87:        strcpy(path, ".");

opal/mca/pmix/pmix4x/pmix/src/util/path.c
152:                    strcpy(pfix, env);

opal/mca/pmix/pmix4x/pmix/src/util/printf.c
273:            strcpy(str, buf);

opal/mca/pmix/pmix4x/pmix/libtool
6352:  strcpy (newargz[0], actual_cwrapper_path);
6453:  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
6585:		  strcpy (concat_name + tmp_len + 1, wrapper);
6593:		  strcpy (concat_name + p_len + 1, wrapper);
6610:  strcpy (concat_name + tmp_len + 1, wrapper);
6778:          strcpy (new_value, orig_value);
6779:          strcpy (new_value + orig_value_len, add);
6783:          strcpy (new_value, add);
6784:          strcpy (new_value + add_len, orig_value);

opal/test/reachable/reachable_netlink.c
140:                strcpy(addr, "Unknown");
168:                strcpy(addr, "Unknown");

opal/util/opal_pty.c
138:        strcpy(name, line);
162:    strcpy(pts_name, "/dev/ptc");
164:    strcpy(pts_name, "/dev/ptmx");
183:    strcpy(pts_name, ptr);      /* return name of slave */
188:    strcpy(pts_name, "/dev/ptyXY");

opal/util/path.c
153:                    strcpy(pfix, env);

opal/util/printf.c
280:            strcpy(str, buf);

opal/util/info.c
118:               strcpy(value, search->ie_value);

opal/util/os_path.c
60:    	    strcpy(path, ".");
63:    	    strcpy(path, path_sep);
86:        strcpy(path, ".");

orte/mca/ras/slurm/ras_slurm_module.c
735:    strcpy(str, base);

orte/mca/regx/base/regx_base_default_fns.c
1113:        strcpy(str, base);

orte/runtime/data_type_support/orte_dt_print_fns.c
519:                strcpy(locale, "NODE");
522:            strcpy(locale, "UNKNOWN");
525:        strcpy(locale, "UNKNOWN");

orte/test/mpi/client.c
16: strcpy(port_name, argv[1] );  /* assume server's name is cmd-line arg */

test/support/support.c
47:    strcpy(opal_description, a);

libtool
6355:  strcpy (newargz[0], actual_cwrapper_path);
6456:  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
6588:		  strcpy (concat_name + tmp_len + 1, wrapper);
6596:		  strcpy (concat_name + p_len + 1, wrapper);
6613:  strcpy (concat_name + tmp_len + 1, wrapper);
6781:          strcpy (new_value, orig_value);
6782:          strcpy (new_value + orig_value_len, add);
6786:          strcpy (new_value, add);
6787:          strcpy (new_value + add_len, orig_value);

and now for strncpy:

ompi/communicator/comm.c
1321:    strncpy(comm->c_name, name, MPI_MAX_OBJECT_NAME);

ompi/communicator/comm_init.c
143:    strncpy (ompi_mpi_comm_world.comm.c_name, "MPI_COMM_WORLD",
197:    strncpy(ompi_mpi_comm_self.comm.c_name,"MPI_COMM_SELF",strlen("MPI_COMM_SELF")+1);
222:    strncpy(ompi_mpi_comm_null.comm.c_name,"MPI_COMM_NULL",strlen("MPI_COMM_NULL")+1);

ompi/datatype/ompi_datatype_create.c
114:    strncpy(new_ompi_datatype->name, new_name, MPI_MAX_OBJECT_NAME - 1);

ompi/datatype/ompi_datatype_module.c
423:        strncpy( (PDATA)->name, MPIDDTNAME, MPI_MAX_OBJECT_NAME );                   \
441:        strncpy( (PDATA)->name, (MPIDDTNAME), MPI_MAX_OBJECT_NAME );                 \
448:        strncpy( (PDATA)->name, MPIDDTNAME, MPI_MAX_OBJECT_NAME );                   \

ompi/errhandler/errcode-internal.c
82:    strncpy(ompi_success_intern.errstring, "OMPI_SUCCESS", OMPI_MAX_ERROR_STRING);
90:    strncpy(ompi_error_intern.errstring, "OMPI_ERROR", OMPI_MAX_ERROR_STRING);
98:    strncpy(ompi_err_out_of_resource_intern.errstring, "OMPI_ERR_OUT_OF_RESOURCE", OMPI_MAX_ERROR_STRING);
106:    strncpy(ompi_err_temp_out_of_resource_intern.errstring, "OMPI_ERR_TEMP_OUT_OF_RESOURCE", OMPI_MAX_ERROR_STRING);
114:    strncpy(ompi_err_resource_busy_intern.errstring, "OMPI_ERR_RESOURCE_BUSY", OMPI_MAX_ERROR_STRING);
122:    strncpy(ompi_err_bad_param_intern.errstring, "OMPI_ERR_BAD_PARAM", OMPI_MAX_ERROR_STRING);
130:    strncpy(ompi_err_fatal_intern.errstring, "OMPI_ERR_FATAL", OMPI_MAX_ERROR_STRING);
138:    strncpy(ompi_err_not_implemented_intern.errstring, "OMPI_ERR_NOT_IMPLEMENTED", OMPI_MAX_ERROR_STRING);
146:    strncpy(ompi_err_not_supported_intern.errstring, "OMPI_ERR_NOT_SUPPORTED", OMPI_MAX_ERROR_STRING);
154:    strncpy(ompi_err_interupted_intern.errstring, "OMPI_ERR_INTERUPTED", OMPI_MAX_ERROR_STRING);
162:    strncpy(ompi_err_would_block_intern.errstring, "OMPI_ERR_WOULD_BLOCK", OMPI_MAX_ERROR_STRING);
170:    strncpy(ompi_err_in_errno_intern.errstring, "OMPI_ERR_IN_ERRNO", OMPI_MAX_ERROR_STRING);
178:    strncpy(ompi_err_unreach_intern.errstring, "OMPI_ERR_UNREACH", OMPI_MAX_ERROR_STRING);
186:    strncpy(ompi_err_not_found_intern.errstring, "OMPI_ERR_NOT_FOUND", OMPI_MAX_ERROR_STRING);
194:    strncpy(ompi_err_buffer_intern.errstring, "OMPI_ERR_BUFFER", OMPI_MAX_ERROR_STRING);
202:    strncpy(ompi_err_request_intern.errstring, "OMPI_ERR_REQUEST", OMPI_MAX_ERROR_STRING);
210:    strncpy(ompi_err_rma_sync_intern.errstring, "OMPI_ERR_RMA_SYNC", OMPI_MAX_ERROR_STRING);
218:    strncpy(ompi_err_rma_shared_intern.errstring, "OMPI_ERR_RMA_SHARED", OMPI_MAX_ERROR_STRING);
226:    strncpy(ompi_err_rma_attach_intern.errstring, "OMPI_ERR_RMA_ATTACH", OMPI_MAX_ERROR_STRING);
234:    strncpy(ompi_err_rma_range_intern.errstring, "OMPI_ERR_RMA_RANGE", OMPI_MAX_ERROR_STRING);
242:    strncpy(ompi_err_rma_conflict_intern.errstring, "OMPI_ERR_RMA_CONFLICT", OMPI_MAX_ERROR_STRING);
250:    strncpy(ompi_err_win_intern.errstring, "OMPI_ERR_WIN", OMPI_MAX_ERROR_STRING);
258:    strncpy(ompi_err_rma_flavor_intern.errstring, "OMPI_ERR_RMA_FLAVOR", OMPI_MAX_ERROR_STRING);

ompi/errhandler/errcode.c
127:    strncpy((VAR).errstring, (TXT), MPI_MAX_ERROR_STRING);                \
356:    strncpy ( errcodep->errstring, errstring, len );

ompi/errhandler/errhandler.c
101:  strncpy (ompi_mpi_errhandler_null.eh.eh_name, "MPI_ERRHANDLER_NULL",
114:  strncpy (ompi_mpi_errors_are_fatal.eh.eh_name, "MPI_ERRORS_ARE_FATAL",
126:  strncpy (ompi_mpi_errors_return.eh.eh_name, "MPI_ERRORS_RETURN",
145:  strncpy (ompi_mpi_errors_throw_exceptions.eh.eh_name, "MPI_ERRORS_THROW_EXCEPTIONS",

ompi/mca/fs/base/fs_base_get_parent_dir.c
89:    if (!slash) strncpy(dir, ".", 2);

ompi/mca/io/romio321/romio/adio/ad_ntfs/ad_ntfs_iwrite.c
32:	strncpy(errMsg, "\0", errMsgLen);
36:	strncpy(errMsg, str, errMsgLen);

ompi/mca/pml/v/pml_v_component.c
148:    strncpy(mca_pml_base_selected_component.pmlm_version.mca_component_name,

ompi/mca/rte/pmix/rte_pmix_module.c
432:        (void)strncpy(jobid_string, OPAL_SCHEMA_WILDCARD_STRING, size);

ompi/mpi/c/comm_get_name.c
75:        strncpy(name, comm->c_name, MPI_MAX_OBJECT_NAME);

ompi/mpi/c/error_string.c
56:    strncpy(string, tmpstring, MPI_MAX_ERROR_STRING);

ompi/mpi/c/lookup_name.c
141:    strncpy ( port_name, pdat->value.data.string, MPI_MAX_PORT_NAME );

ompi/mpi/c/type_create_f90_complex.c
113:        strncpy(datatype->name, new_name, max_len - 1);

ompi/mpi/c/type_create_f90_integer.c
109:        strncpy(datatype->name, new_name, max_len - 1);

ompi/mpi/c/type_create_f90_real.c
113:        strncpy(datatype->name, new_name, max_len - 1);

ompi/mpi/c/type_get_name.c
74:   strncpy(type_name, type->name, MPI_MAX_OBJECT_NAME);

ompi/mpi/c/type_set_name.c
69:    strncpy( type->name, type_name, length );

ompi/mpi/fortran/base/strings.c
68:        strncpy(*cstr, fstr, len);
94:    strncpy(fstr, cstr, len);

ompi/mpi/tool/mpit-internal.h
67:        strncpy (dest, source, *len);

ompi/mpiext/affinity/c/mpiext_affinity_str.c
104:        strncpy(str, ompi_nobind_str, OMPI_AFFINITY_STRING_MAX - 1);
116:        strncpy(str, not_bound_str, OMPI_AFFINITY_STRING_MAX - 1);
166:            strncpy(str, not_bound_str, OMPI_AFFINITY_STRING_MAX - 1);
296:        strncpy(str, ompi_nobind_str, OMPI_AFFINITY_STRING_MAX - 1);
309:        strncpy(str, not_bound_str, OMPI_AFFINITY_STRING_MAX - 1);
359:            strncpy(str, not_bound_str, OMPI_AFFINITY_STRING_MAX - 1);

ompi/mpiext/cr/c/migrate.c
62:        strncpy(loc_hostname, hostname, strlen(hostname));

ompi/op/op.c
359:    strncpy(new_op->o_name, "USER OP", sizeof(new_op->o_name) - 1);
426:    strncpy(op->o_name, name, sizeof(op->o_name) - 1);

ompi/win/win.c
387:    strncpy(win->w_name, win_name, MPI_MAX_OBJECT_NAME);
399:    strncpy(win_name, win->w_name, MPI_MAX_OBJECT_NAME);

opal/mca/base/mca_base_component_repository.c
170:    /* strncpy does not guarantee a \0 */
172:    strncpy (ri->ri_type, type, MCA_BASE_MAX_TYPE_NAME_LEN);
175:    strncpy (ri->ri_name, name, MCA_BASE_MAX_COMPONENT_NAME_LEN);

opal/mca/btl/openib/btl_openib_ini.c
327:    strncpy(key_buffer, btl_openib_ini_yytext, key_buffer_len);
opal/mca/btl/usnic/btl_usnic_cagent.c
1192:    strncpy(address.sun_path, ipc_filename, sizeof(address.sun_path) - 1);

opal/mca/btl/usnic/btl_usnic_cclient.c
106:    strncpy(address.sun_path, ipc_filename, sizeof(address.sun_path) - 1);
198:    strncpy(cmd.nodename, opal_process_info.nodename,
200:    strncpy(cmd.usnic_name, module->linux_device_name,
258:    strncpy(cmd.dest_nodename, dest_nodename, CONNECTIVITY_NODENAME_LEN - 1);

opal/mca/btl/usnic/btl_usnic_proc.c
242:        strncpy(protostr, fi_tostr(&proto, FI_TYPE_PROTOCOL),

opal/mca/hwloc/hwloc201/hwloc/hwloc/topology-linux.c
4308:	strncpy(data->utsname.sysname, line+8, sizeof(data->utsname.sysname));
4313:	strncpy(data->utsname.release, line+11, sizeof(data->utsname.release));
4318:	strncpy(data->utsname.version, line+11, sizeof(data->utsname.version));
4323:	strncpy(data->utsname.nodename, line+10, sizeof(data->utsname.nodename));
4328:	strncpy(data->utsname.machine, line+14, sizeof(data->utsname.machine));
4992:      strncpy(vendor, prop, sizeof(vendor));
4997:      strncpy(model, prop, sizeof(model));
5002:      strncpy(revision, prop, sizeof(revision));
5007:      strncpy(serial, prop, sizeof(serial));
5012:      strncpy(blocktype, prop, sizeof(blocktype));
5031:      strncpy(vendor, line+strlen("E:ID_VENDOR="), sizeof(vendor));
5034:      strncpy(model, line+strlen("E:ID_MODEL="), sizeof(model));
5037:      strncpy(revision, line+strlen("E:ID_REVISION="), sizeof(revision));
5040:      strncpy(serial, line+strlen("E:ID_SERIAL_SHORT="), sizeof(serial));
5043:      strncpy(blocktype, line+strlen("E:ID_TYPE="), sizeof(blocktype));

opal/mca/hwloc/hwloc201/hwloc/hwloc/topology-solaris-chiptype.c
302:      strncpy(&dss_chip_type[0], string_val, PICL_PROPNAMELEN_MAX);
304:      strncpy(&dss_chip_model[0], string_val, PICL_PROPNAMELEN_MAX);
465:      strncpy(dss_chip_model, sparc_modes[dss_chip_mode],

opal/mca/if/bsdx_ipv4/if_bsdx.c
128:        strncpy(intf->if_name, cur_ifaddrs->ifa_name, IF_NAMESIZE);

opal/mca/if/bsdx_ipv6/if_bsdx_ipv6.c
201:        strncpy(intf->if_name, cur_ifaddrs->ifa_name, IF_NAMESIZE);

opal/mca/if/linux_ipv6/if_linux_ipv6.c
146:            strncpy(intf->if_name, ifname, IF_NAMESIZE);

opal/mca/if/posix_ipv4/if_posix.c
221:        strncpy(intf->if_name, ifr->ifr_name, sizeof(intf->if_name) - 1);

opal/mca/if/solaris_ipv6/if_solaris_ipv6.c
99:        strncpy (lifquery.lifr_name, lifreq->lifr_name,
143:                strncpy (intf->if_name, lifreq->lifr_name, IF_NAMESIZE);

opal/mca/pmix/ext1x/pmix1x_client.c
137:    (void)strncpy(job->nspace, my_proc.nspace, PMIX_MAX_NSLEN);
202:            (void)strncpy(parray[n].nspace, job->nspace, PMIX_MAX_NSLEN);
246:        (void)strncpy(p.nspace, job->nspace, PMIX_MAX_NSLEN);
250:        (void)strncpy(p.nspace, my_proc.nspace, PMIX_MAX_NSLEN);
311:            (void)strncpy(parray[n].nspace, job->nspace, PMIX_MAX_NSLEN);
318:        (void)strncpy(info.key, PMIX_COLLECT_DATA, PMIX_MAX_KEYLEN);
373:            (void)strncpy(parray[n].nspace, job->nspace, PMIX_MAX_NSLEN);
381:        (void)strncpy(info.key, PMIX_COLLECT_DATA, PMIX_MAX_KEYLEN);
467:        (void)strncpy(p.nspace, job->nspace, PMIX_MAX_NSLEN);
495:                (void)strncpy(pinfo[n].key, OPAL_PMIX_OPTIONAL, PMIX_MAX_KEYLEN);
498:                (void)strncpy(pinfo[n].key, ival->key, PMIX_MAX_KEYLEN);
580:        (void)strncpy(op->p.nspace, job->nspace, PMIX_MAX_NSLEN);
583:        (void)strncpy(op->p.nspace, my_proc.nspace, PMIX_MAX_NSLEN);
592:                (void)strncpy(op->info[n].key, OPAL_PMIX_OPTIONAL, PMIX_MAX_KEYLEN);
595:                (void)strncpy(op->info[n].key, ival->key, PMIX_MAX_KEYLEN);
630:            (void)strncpy(pinfo[n].key, iptr->key, PMIX_MAX_KEYLEN);
671:            (void)strncpy(op->info[n].key, iptr->key, PMIX_MAX_KEYLEN);
707:        (void)strncpy(pdata[n++].key, d->value.key, PMIX_MAX_KEYLEN);
714:            (void)strncpy(pinfo[n].key, iptr->key, PMIX_MAX_KEYLEN);
749:                (void)strncpy(job->nspace, pdata[n].proc.nspace, PMIX_MAX_NSLEN);
812:                (void)strncpy(job->nspace, data[n].proc.nspace, PMIX_MAX_NSLEN);
862:            (void)strncpy(op->info[n].key, iptr->key, PMIX_MAX_KEYLEN);
884:            (void)strncpy(pinfo[n].key, iptr->key, PMIX_MAX_KEYLEN);
916:            (void)strncpy(op->info[n].key, iptr->key, PMIX_MAX_KEYLEN);
942:            (void)strncpy(pinfo[n].key, info->key, PMIX_MAX_KEYLEN);
961:                (void)strncpy(papps[n].info[m].key, info->key, PMIX_MAX_KEYLEN);
982:        (void)strncpy(job->nspace, nspace, PMIX_MAX_NSLEN);
1015:        (void)strncpy(job->nspace, nspace, PMIX_MAX_NSLEN);
1042:            (void)strncpy(op->info[n].key, info->key, PMIX_MAX_KEYLEN);
1061:                (void)strncpy(op->apps[n].info[m].key, info->key, PMIX_MAX_KEYLEN);
1105:        (void)strncpy(parray[n].nspace, job->nspace, PMIX_MAX_NSLEN);
1150:                (void)strncpy(op->procs[n].nspace, job->nspace, PMIX_MAX_NSLEN);
1189:                (void)strncpy(parray[n].nspace, job->nspace, PMIX_MAX_NSLEN);
1237:                (void)strncpy(op->procs[n].nspace, job->nspace, PMIX_MAX_NSLEN);
1308:                (void)strncpy(job->nspace, nspace, PMIX_MAX_NSLEN);

opal/mca/pmix/ext1x/pmix1x_server_north.c
422:                (void)strncpy(d[n].key, p->value.key, PMIX_MAX_KEYLEN);

opal/mca/pmix/ext1x/pmix1x_server_south.c
146:            (void)strncpy(pinfo[n].key, kv->key, PMIX_MAX_KEYLEN);
245:    (void)strncpy(job->nspace, nspace, PMIX_MAX_NSLEN);
254:            (void)strncpy(pinfo[n].key, kv->key, PMIX_MAX_KEYLEN);
267:                        (void)strncpy(pmap[m].key, k2->key, PMIX_MAX_KEYLEN);
355:            (void)strncpy(p.nspace, jptr->nspace, PMIX_MAX_NSLEN);
436:            (void)strncpy(pinfo[n].key, kv->key, PMIX_MAX_KEYLEN);

opal/mca/pmix/ext1x/pmix1x.c
127:    (void)strncpy(jptr->nspace, nspace, PMIX_MAX_NSLEN);

opal/mca/pmix/ext2x/ext2x_client.c
93:            (void)strncpy(pinfo[n].key, ival->key, PMIX_MAX_KEYLEN);
134:    (void)strncpy(job->nspace, my_proc.nspace, PMIX_MAX_NSLEN);
213:            (void)strncpy(pinfo[n].key, val->key, PMIX_MAX_KEYLEN);
219:                (void)strncpy(my_proc.nspace, val->data.string, PMIX_MAX_NSLEN);
258:    (void)strncpy(job->nspace, my_proc.nspace, PMIX_MAX_NSLEN);
352:            (void)strncpy(parray[n].nspace, nsptr, PMIX_MAX_NSLEN);
393:        (void)strncpy(p.nspace, nsptr, PMIX_MAX_NSLEN);
397:        (void)strncpy(p.nspace, my_proc.nspace, PMIX_MAX_NSLEN);
465:            (void)strncpy(parray[n].nspace, nsptr, PMIX_MAX_NSLEN);
474:        (void)strncpy(info.key, PMIX_COLLECT_DATA, PMIX_MAX_KEYLEN);
525:            (void)strncpy(parray[n].nspace, nsptr, PMIX_MAX_NSLEN);
621:        (void)strncpy(p.nspace, my_proc.nspace, PMIX_MAX_NSLEN);
628:        (void)strncpy(p.nspace, nsptr, PMIX_MAX_NSLEN);
637:            (void)strncpy(pinfo[n].key, ival->key, PMIX_MAX_KEYLEN);
742:        (void)strncpy(op->p.nspace, my_proc.nspace, PMIX_MAX_NSLEN);
749:        (void)strncpy(op->p.nspace, nsptr, PMIX_MAX_NSLEN);
758:            (void)strncpy(op->info[n].key, val->key, PMIX_MAX_KEYLEN);
799:            (void)strncpy(pinfo[n].key, iptr->key, PMIX_MAX_KEYLEN);
847:            (void)strncpy(op->info[n].key, iptr->key, PMIX_MAX_KEYLEN);
885:        (void)strncpy(pdata[n].key, d->value.key, PMIX_MAX_KEYLEN);
893:            (void)strncpy(pinfo[n].key, iptr->key, PMIX_MAX_KEYLEN);
924:                (void)strncpy(job->nspace, pdata[n].proc.nspace, PMIX_MAX_NSLEN);
986:                (void)strncpy(job->nspace, data[n].proc.nspace, PMIX_MAX_NSLEN);
1042:            (void)strncpy(op->info[n].key, iptr->key, PMIX_MAX_KEYLEN);
1070:            (void)strncpy(pinfo[n].key, iptr->key, PMIX_MAX_KEYLEN);
1109:            (void)strncpy(op->info[n].key, iptr->key, PMIX_MAX_KEYLEN);
1144:            (void)strncpy(info[n].key, ival->key, PMIX_MAX_KEYLEN);
1169:                (void)strncpy(papps[n].info[m].key, ival->key, PMIX_MAX_KEYLEN);
1191:        (void)strncpy(job->nspace, nspace, PMIX_MAX_NSLEN);
1225:        (void)strncpy(job->nspace, nspace, PMIX_MAX_NSLEN);
1260:            (void)strncpy(op->info[n].key, info->key, PMIX_MAX_KEYLEN);
1282:                (void)strncpy(op->apps[n].info[m].key, info->key, PMIX_MAX_KEYLEN);
1328:        (void)strncpy(p[n].nspace, nsptr, PMIX_MAX_NSLEN);
1380:        (void)strncpy(op->procs[n].nspace, nsptr, PMIX_MAX_NSLEN);
1426:        (void)strncpy(p[n].nspace, nsptr, PMIX_MAX_NSLEN);
1478:        (void)strncpy(op->procs[n].nspace, nsptr, PMIX_MAX_NSLEN);
1537:                (void)strncpy(job->nspace, array[n].nspace, PMIX_MAX_NSLEN);
1638:            (void)strncpy(op->procs[n].nspace, nsptr, PMIX_MAX_NSLEN);
1649:            (void)strncpy(op->info[n].key, iptr->key, PMIX_MAX_KEYLEN);

opal/mca/pmix/ext2x/ext2x_server_north.c
496:                (void)strncpy(d[n].key, p->value.key, PMIX_MAX_KEYLEN);
931:            (void)strncpy(pcaddy->info[n].key, kv->key, PMIX_MAX_KEYLEN);
1028:        (void)strncpy(job->nspace, p.nspace, PMIX_MAX_NSLEN);

opal/mca/pmix/ext2x/ext2x_server_south.c
125:            (void)strncpy(pinfo[n].key, kv->key, PMIX_MAX_KEYLEN);
262:    (void)strncpy(job->nspace, nspace, PMIX_MAX_NSLEN);
272:            (void)strncpy(pinfo[n].key, kv->key, PMIX_MAX_KEYLEN);
287:                        (void)strncpy(pmap[m].key, k2->key, PMIX_MAX_KEYLEN);
419:            (void)strncpy(p.nspace, jptr->nspace, PMIX_MAX_NSLEN);
527:            (void)strncpy(pinfo[n].key, kv->key, PMIX_MAX_KEYLEN);

opal/mca/pmix/ext2x/ext2x.c
178:    (void)strncpy(jptr->nspace, nspace, PMIX_MAX_NSLEN);
210:                (void)strncpy(op->info[n].key, kv->key, PMIX_MAX_KEYLEN);
774:                    (void)strncpy(v->data.proc->nspace, job->nspace, PMIX_MAX_NSLEN);
827:                    (void)strncpy(info[n].key, val->key, PMIX_MAX_KEYLEN);
1081:            (void)strncpy(op->info[n].key, kv->key, PMIX_MAX_KEYLEN);
1180:        (void)strncpy(p.nspace, nsptr, PMIX_MAX_NSLEN);
1194:            (void)strncpy(op->info[n].key, kv->key, PMIX_MAX_KEYLEN);
1305:                (void)strncpy(cd->queries[n].qualifiers[nq].key, ival->key, PMIX_MAX_KEYLEN);
1368:        (void)strncpy(cd->info[n].key, ival->key, PMIX_MAX_KEYLEN);

opal/mca/pmix/ext3x/ext3x.c
187:    (void)strncpy(jptr->nspace, nspace, PMIX_MAX_NSLEN);
219:                (void)strncpy(op->info[n].key, kv->key, PMIX_MAX_KEYLEN);
847:                    (void)strncpy(v->data.proc->nspace, job->nspace, PMIX_MAX_NSLEN);
908:                        (void)strncpy(info[n].key, val->key, PMIX_MAX_KEYLEN);
924:                    (void)strncpy(v->data.pinfo->proc.nspace, job->nspace, PMIX_MAX_NSLEN);
1306:            (void)strncpy(op->info[n].key, kv->key, PMIX_MAX_KEYLEN);
1405:        (void)strncpy(p.nspace, nsptr, PMIX_MAX_NSLEN);
1419:            (void)strncpy(op->info[n].key, kv->key, PMIX_MAX_KEYLEN);
1531:                (void)strncpy(cd->queries[n].qualifiers[nq].key, ival->key, PMIX_MAX_KEYLEN);
1594:        (void)strncpy(cd->info[n].key, ival->key, PMIX_MAX_KEYLEN);

opal/mca/pmix/ext3x/ext3x_client.c
92:            (void)strncpy(pinfo[n].key, ival->key, PMIX_MAX_KEYLEN);
138:    (void)strncpy(job->nspace, mca_pmix_ext3x_component.myproc.nspace, PMIX_MAX_NSLEN);
217:            (void)strncpy(pinfo[n].key, val->key, PMIX_MAX_KEYLEN);
223:                (void)strncpy(mca_pmix_ext3x_component.myproc.nspace, val->data.string, PMIX_MAX_NSLEN);
262:    (void)strncpy(job->nspace, mca_pmix_ext3x_component.myproc.nspace, PMIX_MAX_NSLEN);
356:            (void)strncpy(parray[n].nspace, nsptr, PMIX_MAX_NSLEN);
397:        (void)strncpy(p.nspace, nsptr, PMIX_MAX_NSLEN);
401:        (void)strncpy(p.nspace, mca_pmix_ext3x_component.myproc.nspace, PMIX_MAX_NSLEN);
470:            (void)strncpy(parray[n].nspace, nsptr, PMIX_MAX_NSLEN);
479:        (void)strncpy(info.key, PMIX_COLLECT_DATA, PMIX_MAX_KEYLEN);
530:            (void)strncpy(parray[n].nspace, nsptr, PMIX_MAX_NSLEN);
626:        (void)strncpy(p.nspace, mca_pmix_ext3x_component.myproc.nspace, PMIX_MAX_NSLEN);
633:        (void)strncpy(p.nspace, nsptr, PMIX_MAX_NSLEN);
642:            (void)strncpy(pinfo[n].key, ival->key, PMIX_MAX_KEYLEN);
747:        (void)strncpy(op->p.nspace, mca_pmix_ext3x_component.myproc.nspace, PMIX_MAX_NSLEN);
754:        (void)strncpy(op->p.nspace, nsptr, PMIX_MAX_NSLEN);
763:            (void)strncpy(op->info[n].key, val->key, PMIX_MAX_KEYLEN);
804:            (void)strncpy(pinfo[n].key, iptr->key, PMIX_MAX_KEYLEN);
852:            (void)strncpy(op->info[n].key, iptr->key, PMIX_MAX_KEYLEN);
890:        (void)strncpy(pdata[n].key, d->value.key, PMIX_MAX_KEYLEN);
898:            (void)strncpy(pinfo[n].key, iptr->key, PMIX_MAX_KEYLEN);
929:                (void)strncpy(job->nspace, pdata[n].proc.nspace, PMIX_MAX_NSLEN);
991:                (void)strncpy(job->nspace, data[n].proc.nspace, PMIX_MAX_NSLEN);
1047:            (void)strncpy(op->info[n].key, iptr->key, PMIX_MAX_KEYLEN);
1075:            (void)strncpy(pinfo[n].key, iptr->key, PMIX_MAX_KEYLEN);
1114:            (void)strncpy(op->info[n].key, iptr->key, PMIX_MAX_KEYLEN);
1149:            (void)strncpy(info[n].key, ival->key, PMIX_MAX_KEYLEN);
1174:                (void)strncpy(papps[n].info[m].key, ival->key, PMIX_MAX_KEYLEN);
1196:        (void)strncpy(job->nspace, nspace, PMIX_MAX_NSLEN);
1230:        (void)strncpy(job->nspace, nspace, PMIX_MAX_NSLEN);
1265:            (void)strncpy(op->info[n].key, info->key, PMIX_MAX_KEYLEN);
1287:                (void)strncpy(op->apps[n].info[m].key, info->key, PMIX_MAX_KEYLEN);
1333:        (void)strncpy(p[n].nspace, nsptr, PMIX_MAX_NSLEN);
1385:        (void)strncpy(op->procs[n].nspace, nsptr, PMIX_MAX_NSLEN);
1430:        (void)strncpy(p[n].nspace, nsptr, PMIX_MAX_NSLEN);
1482:        (void)strncpy(op->procs[n].nspace, nsptr, PMIX_MAX_NSLEN);
1541:                (void)strncpy(job->nspace, array[n].nspace, PMIX_MAX_NSLEN);
1642:            (void)strncpy(op->procs[n].nspace, nsptr, PMIX_MAX_NSLEN);
1653:            (void)strncpy(op->info[n].key, iptr->key, PMIX_MAX_KEYLEN);

opal/mca/pmix/ext3x/ext3x_server_north.c
511:                (void)strncpy(d[n].key, p->value.key, PMIX_MAX_KEYLEN);
946:            (void)strncpy(pcaddy->info[n].key, kv->key, PMIX_MAX_KEYLEN);
1054:        (void)strncpy(job->nspace, p.nspace, PMIX_MAX_NSLEN);

opal/mca/pmix/ext3x/ext3x_server_south.c
126:            (void)strncpy(pinfo[n].key, kv->key, PMIX_MAX_KEYLEN);
267:    (void)strncpy(job->nspace, nspace, PMIX_MAX_NSLEN);
277:            (void)strncpy(pinfo[n].key, kv->key, PMIX_MAX_KEYLEN);
292:                        (void)strncpy(pmap[m].key, k2->key, PMIX_MAX_KEYLEN);
424:            (void)strncpy(p.nspace, jptr->nspace, PMIX_MAX_NSLEN);
532:            (void)strncpy(pinfo[n].key, kv->key, PMIX_MAX_KEYLEN);
715:            (void)strncpy(pinfo[n].key, kv->key, PMIX_MAX_KEYLEN);
767:            (void)strncpy(pinfo[n].key, kv->key, PMIX_MAX_KEYLEN);

opal/mca/pmix/pmix4x/pmix4x.c
187:    (void)strncpy(jptr->nspace, nspace, PMIX_MAX_NSLEN);
219:                (void)strncpy(op->info[n].key, kv->key, PMIX_MAX_KEYLEN);
847:                    (void)strncpy(v->data.proc->nspace, job->nspace, PMIX_MAX_NSLEN);
908:                        (void)strncpy(info[n].key, val->key, PMIX_MAX_KEYLEN);
924:                    (void)strncpy(v->data.pinfo->proc.nspace, job->nspace, PMIX_MAX_NSLEN);
1306:            (void)strncpy(op->info[n].key, kv->key, PMIX_MAX_KEYLEN);
1405:        (void)strncpy(p.nspace, nsptr, PMIX_MAX_NSLEN);
1419:            (void)strncpy(op->info[n].key, kv->key, PMIX_MAX_KEYLEN);
1531:                (void)strncpy(cd->queries[n].qualifiers[nq].key, ival->key, PMIX_MAX_KEYLEN);
1594:        (void)strncpy(cd->info[n].key, ival->key, PMIX_MAX_KEYLEN);

opal/mca/pmix/pmix4x/pmix4x_client.c
92:            (void)strncpy(pinfo[n].key, ival->key, PMIX_MAX_KEYLEN);
138:    (void)strncpy(job->nspace, mca_pmix_pmix4x_component.myproc.nspace, PMIX_MAX_NSLEN);
217:            (void)strncpy(pinfo[n].key, val->key, PMIX_MAX_KEYLEN);
223:                (void)strncpy(mca_pmix_pmix4x_component.myproc.nspace, val->data.string, PMIX_MAX_NSLEN);
262:    (void)strncpy(job->nspace, mca_pmix_pmix4x_component.myproc.nspace, PMIX_MAX_NSLEN);
356:            (void)strncpy(parray[n].nspace, nsptr, PMIX_MAX_NSLEN);
397:        (void)strncpy(p.nspace, nsptr, PMIX_MAX_NSLEN);
401:        (void)strncpy(p.nspace, mca_pmix_pmix4x_component.myproc.nspace, PMIX_MAX_NSLEN);
470:            (void)strncpy(parray[n].nspace, nsptr, PMIX_MAX_NSLEN);
479:        (void)strncpy(info.key, PMIX_COLLECT_DATA, PMIX_MAX_KEYLEN);
530:            (void)strncpy(parray[n].nspace, nsptr, PMIX_MAX_NSLEN);
626:        (void)strncpy(p.nspace, mca_pmix_pmix4x_component.myproc.nspace, PMIX_MAX_NSLEN);
633:        (void)strncpy(p.nspace, nsptr, PMIX_MAX_NSLEN);
642:            (void)strncpy(pinfo[n].key, ival->key, PMIX_MAX_KEYLEN);
747:        (void)strncpy(op->p.nspace, mca_pmix_pmix4x_component.myproc.nspace, PMIX_MAX_NSLEN);
754:        (void)strncpy(op->p.nspace, nsptr, PMIX_MAX_NSLEN);
763:            (void)strncpy(op->info[n].key, val->key, PMIX_MAX_KEYLEN);
804:            (void)strncpy(pinfo[n].key, iptr->key, PMIX_MAX_KEYLEN);
852:            (void)strncpy(op->info[n].key, iptr->key, PMIX_MAX_KEYLEN);
890:        (void)strncpy(pdata[n].key, d->value.key, PMIX_MAX_KEYLEN);
898:            (void)strncpy(pinfo[n].key, iptr->key, PMIX_MAX_KEYLEN);
929:                (void)strncpy(job->nspace, pdata[n].proc.nspace, PMIX_MAX_NSLEN);
991:                (void)strncpy(job->nspace, data[n].proc.nspace, PMIX_MAX_NSLEN);
1047:            (void)strncpy(op->info[n].key, iptr->key, PMIX_MAX_KEYLEN);
1075:            (void)strncpy(pinfo[n].key, iptr->key, PMIX_MAX_KEYLEN);
1114:            (void)strncpy(op->info[n].key, iptr->key, PMIX_MAX_KEYLEN);
1149:            (void)strncpy(info[n].key, ival->key, PMIX_MAX_KEYLEN);
1174:                (void)strncpy(papps[n].info[m].key, ival->key, PMIX_MAX_KEYLEN);
1196:        (void)strncpy(job->nspace, nspace, PMIX_MAX_NSLEN);
1230:        (void)strncpy(job->nspace, nspace, PMIX_MAX_NSLEN);
1265:            (void)strncpy(op->info[n].key, info->key, PMIX_MAX_KEYLEN);
1287:                (void)strncpy(op->apps[n].info[m].key, info->key, PMIX_MAX_KEYLEN);
1333:        (void)strncpy(p[n].nspace, nsptr, PMIX_MAX_NSLEN);
1385:        (void)strncpy(op->procs[n].nspace, nsptr, PMIX_MAX_NSLEN);
1430:        (void)strncpy(p[n].nspace, nsptr, PMIX_MAX_NSLEN);
1482:        (void)strncpy(op->procs[n].nspace, nsptr, PMIX_MAX_NSLEN);
1541:                (void)strncpy(job->nspace, array[n].nspace, PMIX_MAX_NSLEN);
1642:            (void)strncpy(op->procs[n].nspace, nsptr, PMIX_MAX_NSLEN);
1653:            (void)strncpy(op->info[n].key, iptr->key, PMIX_MAX_KEYLEN);

opal/mca/pmix/pmix4x/pmix4x_server_north.c
511:                (void)strncpy(d[n].key, p->value.key, PMIX_MAX_KEYLEN);
946:            (void)strncpy(pcaddy->info[n].key, kv->key, PMIX_MAX_KEYLEN);
1054:        (void)strncpy(job->nspace, p.nspace, PMIX_MAX_NSLEN);

opal/mca/pmix/pmix4x/pmix4x_server_south.c
126:            (void)strncpy(pinfo[n].key, kv->key, PMIX_MAX_KEYLEN);
267:    (void)strncpy(job->nspace, nspace, PMIX_MAX_NSLEN);
277:            (void)strncpy(pinfo[n].key, kv->key, PMIX_MAX_KEYLEN);
292:                        (void)strncpy(pmap[m].key, k2->key, PMIX_MAX_KEYLEN);
424:            (void)strncpy(p.nspace, jptr->nspace, PMIX_MAX_NSLEN);
532:            (void)strncpy(pinfo[n].key, kv->key, PMIX_MAX_KEYLEN);
715:            (void)strncpy(pinfo[n].key, kv->key, PMIX_MAX_KEYLEN);
767:            (void)strncpy(pinfo[n].key, kv->key, PMIX_MAX_KEYLEN);

opal/mca/pstat/test/pstat_test.c
87:        strncpy(stats->node, hostname, OPAL_PSTAT_MAX_STRING_LEN);
90:        strncpy(stats->cmd, "UNKNOWN", OPAL_PSTAT_MAX_STRING_LEN);

opal/mca/rcache/udreg/rcache_udreg_module.c
95:    strncpy (cache_attr.cache_name, rcache->resources.base.cache_name, UDREG_MAX_CACHENAME_LEN);

opal/mca/reachable/netlink/reachable_netlink_module.c
95:    strncpy(str_local,
99:    strncpy(str_remote,

opal/mca/reachable/weighted/reachable_weighted.c
123:    strncpy(str_local, opal_net_get_hostname(local_sockaddr), sizeof(str_local));
125:    strncpy(str_remote, opal_net_get_hostname(remote_sockaddr), sizeof(str_remote));

opal/mca/shmem/mmap/shmem_mmap_module.c
440:        (void)strncpy(ds_buf->seg_name, real_file_name, OPAL_PATH_MAX - 1);

opal/test/reachable/reachable_shared.h
26:    strncpy(interface->if_name, "interface0", IF_NAMESIZE);

opal/util/Makefile.am
73:        strncpy.h \
112:        strncpy.c \

opal/util/argv.c
218:      strncpy(argtemp, src_string, arglen);
232:      strncpy(arg, src_string, arglen);

opal/util/basename.c
130:                strncpy_s( ret, (p - filename + 1), filename, p - filename );
132:                strncpy(ret, filename, p - filename);

opal/util/error.c
164:            strncpy(strerrbuf, tmp, buflen);
200:            strncpy(converters[i].project, project, MAX_CONVERTER_PROJECT_LEN);

opal/util/ethtool.c
66:    strncpy(ifr.ifr_name, if_name, IF_NAMESIZE);
67:    /* strncpy does not null terminate when the string is truncated */

opal/util/fd.c
180:        strncpy(str, "Unknown", len);

opal/util/if.c
208:                    strncpy(if_name, intf->if_name, length);
217:                    strncpy(if_name, intf->if_name, length);
466:            strncpy(if_name, intf->if_name, length);
485:            strncpy(if_name, intf->if_name, length);

orte/mca/oob/tcp/oob_tcp_sendrecv.h
112:            (void)strncpy(_s->hdr.routed, (m)->routed,                 \
160:            (void)strncpy(_s->hdr.routed, (m)->routed,                 \
205:        (void)strncpy(_s->hdr.routed, (m)->hdr.routed,                 \

orte/mca/plm/rsh/plm_rsh_component.c
368:        strncpy(cwd, path, OPAL_PATH_MAX - 1);

orte/mca/rmaps/base/rmaps_base_map_job.c
562:                        (void)strncpy(tmp1, "UNBOUND", sizeof(tmp1));
565:                            (void)strncpy(tmp1, "UNBOUND", sizeof(tmp1));
569:                    (void)strncpy(tmp1, "UNBOUND", sizeof(tmp1));

orte/mca/rmaps/rank_file/rmaps_rank_file_lex.c
713:static void yy_flex_strncpy (char *,yyconst char *,int );
1992:static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )

orte/mca/snapc/full/snapc_full_global.c
1384:            strncpy( ((datum->mig_host_pref)[i]), tmp_str, OPAL_MAX_PROCESSOR_NAME);

orte/orted/orted_submit.c
2298:            strncpy(MPIR_attach_fifo, attach_fifo, MPIR_MAX_PATH_LENGTH - 1);
2331:        strncpy(MPIR_attach_fifo, attach_fifo, MPIR_MAX_PATH_LENGTH - 1);

orte/test/system/pmixtool.c
50:    (void)strncpy(info[0].key, PMIX_QUERY_NAMESPACES, PMIX_MAX_KEYLEN);

orte/util/attr.c
190:            strncpy(converters[i].project, project, MAX_CONVERTER_PROJECT_LEN);

orte/util/hostfile/hostfile_lex.c
798:static void yy_flex_strncpy (char *,yyconst char *,int );
2221:static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )

orte/util/name_fns.c
295:        (void)strncpy(jobid_string, ORTE_SCHEMA_WILDCARD_STRING, size);

test/monitoring/check_monitoring.c
368:    strncpy(s1, "hello world!", 13);

I probably missed a few - my copy/paste got tired.

@rhc54
Copy link
Contributor

rhc54 commented Sep 26, 2018

This cries out for a simple search/replace of strncpy with opal_strncpy (and friends), and then fix it in one place. We actually do have an opal_strncpy, you know...

Copy link
Member

@gpaulsen gpaulsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You guys...

@rhc54
Copy link
Contributor

rhc54 commented Sep 27, 2018

Ah, but you see there is a difference. @jsquyres saw one warning and decided to fix it. I see hundreds of them - it all depends on your compiler/environment combination. My point is that fixing one is fine, but this is a one-off fix that doesn't really address the problem. Rather than someone replicating this all over the place, one warning-squash at a time, it would be nice to have a more standardized solution.

I will do it for pmix as we have the same problem there. Ditto for the asprintf warnings. It actually turns out to be rather trivial. 😄

@rhc54
Copy link
Contributor

rhc54 commented Sep 27, 2018

FWIW: see how I dealt with it in PMIx: openpmix/openpmix#843. Note that I had to do it that way due to the use of strncpy in user-facing macros.

@bwbarrett
Copy link
Member

@jsquyres sigh; I somehow read strncat as strncpy(). Getting old sucks.

@jsquyres
Copy link
Member Author

Ok, I see where Ralph is going with this -- I didn't think he was talking about all strcpy()/strncpy() instances.

We certainly could do something like an opal_strncpy(), like what Ralph did in the cited PMIX PR. I make the following humble suggestions, though:

  1. If opal_strncpy() is not going to exhibit the same behavior as strncpy(), we should probably give it a different name -- perhaps opal_string_copy() (yeah, I know, I like long names 😄). This would convey that it's different than strncpy() (e.g., it guarantees to NULL-terminate).
  2. Minor nit: I'd pass the length of the destination array into the new function (vs. length-1), and then do the appropriate "minus one" operation inside the new function. I.e., since we'll be calling this from 6 gabillion places, make it as easy as possible for the caller (i.e., not have to put in len-1 all over the place).
  3. Ralph has a valid point: people will use strcpy() and strncpy() without even thinking about it. We might want to have a #define strcpy #error you should use opal_string_copy() instead! (or something similar) that would cause an obvious compile-time failure, and let the developer know about the new function.

A similar approach could be taken for asprintf() ▶️ opal_asprintf().

@rhc54
Copy link
Contributor

rhc54 commented Sep 27, 2018

I'll politely disagree with your first suggestion - the behavior matches expectations, which admittedly may be incorrect based on the latest man pages (I honestly don't know if/when it changed, or if everyone always made the incorrect assumption). You can do as you please in OMPI 😄

In PMIx, the max length of the name was set to a defined constant, which means that the array has to be one greater. Rather than having everyone remember to pass constant-1 to the function, I opted to let them just pass constant. FWIW: we wound up defining macros and new abstract data types just to help people not make the mistake of defining an array to be length constant instead of constant+1. I agree this isn't a more generalized solution, but seems easier for people to get right for PMIx.

Your third suggestion is a good one - I'll happily take it!

@bwbarrett
Copy link
Member

I'm torn with the opal_strncpy(); generally, we haven't wanted to change behavior with our wrappers, only to make the behavior consistent across implementations. The Linux implementation of strncpy (not adding the '\0') is what the standard requires, so it's not like we're removing ambiguity across implementations.

With opal_asprintf(), the return is at least undefined; we're just defining undefined behavior.

I guess I have a gut reaction that I don't like it, but my reasons are lame enough that I'm not going to fight it.

No code or logic changes

Signed-off-by: Jeff Squyres <jsquyres@cisco.com>
Do essentially the same thing as strncpy(3), but a) ensure to always
terminate the destination buffer with a \0, and b) do not \0-pad to
the right.

Signed-off-by: Jeff Squyres <jsquyres@cisco.com>
In many cases, this was a simple string replace.  In a few places, it
entailed:

1. Updating some comments and removing now-redundant foo[size-1]='\0'
   statements.
2. Updating passing (size-1) to (size) (because opal_string_copy()
   wants the entire destination buffer length).

This commit actually fixes a bunch of potential (yet quite unlikely)
bugs where we could have ended up with non-null-terminated strings.

Signed-off-by: Jeff Squyres <jsquyres@cisco.com>
Signed-off-by: Jeff Squyres <jsquyres@cisco.com>
@jsquyres
Copy link
Member Author

jsquyres commented Sep 27, 2018

I just pushed up some new commits (you should look at the individual commit messages):

  1. I have added opal_string_copy() (per Ralph's "you can do whatever you want in Open MPI" comment 😉).
  2. I have converted all instances of strncpy() in OPAL to use opal_string_copy().

If people like this approach, I can:

  1. Convert all instances of strcpy() in OPAL to use opal_string_copy().
  2. Convert all instances of strcpy() and strncpy() in ORTE, OMPI, and OSHMEM to use opal_string_copy().
  3. Remove opal_strncpy() (because it won't be needed any more -- it's just a portable wrapper around strncpy(), because there was apparently a broken strncpy() on RHAS on Itanium).

Copy link
Member

@gpaulsen gpaulsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've re-reviewed the 4 new commits with all of the changes.

@jsquyres jsquyres changed the title rmaps_base: go full-on defensive programming mode Replace strcpy() and strncpy() with (new) opal_string_copy() Oct 1, 2018
Add a hueristic: if the string copy is "too long", fail an assert().
This is based on the premise that Open MPI doesn't do large string
copies.  So if we see a dest_len that is over a certain threshhold
(currently set at 128K), this is likely a programmer error, and on
debug builds, we should fail an assert().  In production builds, it
will work just fine (assuming that it's not a programmer error).

Signed-off-by: Jeff Squyres <jsquyres@cisco.com>
@rhc54
Copy link
Contributor

rhc54 commented Oct 2, 2018

Hey @jsquyres - I thought you were going to put a #error in here to catch someone using strncpy instead of the new function?

@jsquyres
Copy link
Member Author

jsquyres commented Oct 2, 2018

@rhc54 Yeah, that's the plan -- I didn't want to do it yet, because it would prevent testing what I have done so far. 😉

Copy link
Member

@gpaulsen gpaulsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great to me!
#error on various strcpy functions can come in future PR.

@gpaulsen gpaulsen merged commit 56a55cd into open-mpi:master Oct 4, 2018
@jsquyres
Copy link
Member Author

jsquyres commented Oct 4, 2018

@gpaulsen This PR was not complete. It should not have been merged. 😦

Fortunately, it's not harmful to have been merged, but the PR was only something like 1/6th complete (one set of substitutions on OPAL was done -- the rest of OPAL still needs to be done, and nothing in ORTE or OMPI was done yet).

@gpaulsen
Copy link
Member

gpaulsen commented Oct 5, 2018

Sorry. Would you like me to revert it? Is there a convention on who should merge? I saw that the CI had passed and that it had two good reviews, without the work in progress label.

@jsquyres jsquyres deleted the pr/string-madness branch October 8, 2018 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants