diff --git a/src/api/job_info.c b/src/api/job_info.c index 69053c5d9d54e5d5af3c32e541f501e1e4c64181..df35e9dd39e3bc3b60ca298e4054fd1461f63032 100644 --- a/src/api/job_info.c +++ b/src/api/job_info.c @@ -61,6 +61,7 @@ #include "src/common/parse_time.h" #include "src/common/slurm_auth.h" #include "src/common/slurm_protocol_api.h" +#include "src/common/strlcpy.h" #include "src/common/uid.h" #include "src/common/uthash/uthash.h" #include "src/common/xmalloc.h" @@ -1876,7 +1877,7 @@ slurm_network_callerid (network_callerid_msg_t req, uint32_t *job_id, case RESPONSE_NETWORK_CALLERID: resp = (network_callerid_resp_t*)resp_msg.data; *job_id = resp->job_id; - strncpy(node_name, resp->node_name, node_name_size); + strlcpy(node_name, resp->node_name, node_name_size); break; case RESPONSE_SLURM_RC: rc = ((return_code_msg_t *) resp_msg.data)->return_code; diff --git a/src/api/slurm_pmi.c b/src/api/slurm_pmi.c index 31dcaaaae6e39394335998c2063c4c83eecacbdd..a8ad173db76cfc1f43b939749ffa293497e7a8b7 100644 --- a/src/api/slurm_pmi.c +++ b/src/api/slurm_pmi.c @@ -47,6 +47,7 @@ #include "src/common/slurm_protocol_defs.h" #include "src/common/forward.h" #include "src/common/read_config.h" +#include "src/common/strlcpy.h" #include "src/common/xmalloc.h" #include "src/common/fd.h" #include "src/common/slurm_auth.h" @@ -248,10 +249,9 @@ int slurm_get_kvs_comm_set(kvs_comm_set_t **kvs_set_ptr, /* hostname is not set here, so slurm_get_addr fails slurm_get_addr(&slurm_addr, &port, hostname, sizeof(hostname)); */ port = ntohs(slurm_addr.sin_port); - if ((env_pmi_ifhn = getenv("SLURM_PMI_RESP_IFHN"))) { - strncpy(hostname, env_pmi_ifhn, sizeof(hostname)); - hostname[sizeof(hostname)-1] = 0; - } else + if ((env_pmi_ifhn = getenv("SLURM_PMI_RESP_IFHN"))) + strlcpy(hostname, env_pmi_ifhn, sizeof(hostname)); + else gethostname_short(hostname, sizeof(hostname)); data.task_id = pmi_rank; diff --git a/src/common/cpu_frequency.c b/src/common/cpu_frequency.c index cc5aaf7715d561aa5658f78487eedcdf79bd1a14..a7c6f58c41fcdac1a9b3f1c7cb2162bc6a97d836 100644 --- a/src/common/cpu_frequency.c +++ b/src/common/cpu_frequency.c @@ -53,6 +53,7 @@ #include "src/common/log.h" #include "src/common/slurm_protocol_api.h" #include "src/common/slurm_protocol_defs.h" +#include "src/common/strlcpy.h" #include "src/common/xmalloc.h" #include "src/common/xstring.h" #include "src/common/read_config.h" @@ -1398,15 +1399,12 @@ cpu_freq_govlist_to_string(char* buf, uint16_t bufsz, uint32_t govs) xstrcat(list,"UserSpace"); } } - if (list) { - if (strlen(list) < bufsz) - strcpy(buf, list); - else - strncpy(buf, list, bufsz-1); + if (list) { + strlcpy(buf, list, bufsz); xfree(list); } else { - strncpy(buf,"No Governors defined", bufsz-1); + strlcpy(buf, "No Governors defined", bufsz); } } @@ -1656,7 +1654,7 @@ cpu_freq_debug(char* label, char* noval_str, char* freq_str, int freq_len, error("%s: minimum CPU frequency string too large", __func__); } else { - strncpy(bfmin, noval_str, sizeof(bfmin)); + strlcpy(bfmin, noval_str, sizeof(bfmin)); } } else { sep2 = ""; @@ -1674,7 +1672,7 @@ cpu_freq_debug(char* label, char* noval_str, char* freq_str, int freq_len, error("%s: maximum CPU frequency string too large", __func__); } else { - strncpy(bfmax, noval_str, sizeof(bfmax)); + strlcpy(bfmax, noval_str, sizeof(bfmax)); } } else { sep3 = ""; @@ -1688,7 +1686,7 @@ cpu_freq_debug(char* label, char* noval_str, char* freq_str, int freq_len, error("%s: max CPU governor string too large", __func__); } else { - strncpy(bfgov, noval_str, sizeof(bfgov)); + strlcpy(bfgov, noval_str, sizeof(bfgov)); } } if (rc) { diff --git a/src/common/env.c b/src/common/env.c index c9d2ce673ac5810eb7ac9ef20969fd2ca9b48c22..ddeeccf174967739deff8e0daad169bb2977046e 100644 --- a/src/common/env.c +++ b/src/common/env.c @@ -63,6 +63,7 @@ #include "src/common/slurm_protocol_api.h" #include "src/common/slurm_step_layout.h" #include "src/common/slurmdb_defs.h" +#include "src/common/strlcpy.h" #include "src/common/xassert.h" #include "src/common/xmalloc.h" #include "src/common/xstring.h" @@ -1675,15 +1676,13 @@ static int _env_array_entry_splitter(const char *entry, len = ptr - entry; if (len > name_len-1) return 0; - strncpy(name, entry, len); - name[len] = '\0'; + strlcpy(name, entry, len); ptr = ptr + 1; len = strlen(ptr); if (len > value_len-1) return 0; - strncpy(value, ptr, len); - value[len] = '\0'; + strlcpy(value, ptr, len); return 1; } diff --git a/src/common/gres.c b/src/common/gres.c index ab767d3ca97ecc275a3dc423df5779a956207536..1cbb9067804402e4ce68d84fa0b5bc227d1e9a1f 100644 --- a/src/common/gres.c +++ b/src/common/gres.c @@ -78,6 +78,7 @@ typedef cpuset_t cpu_set_t; #include "src/common/plugrack.h" #include "src/common/read_config.h" #include "src/common/slurm_protocol_api.h" +#include "src/common/strlcpy.h" #include "src/common/xmalloc.h" #include "src/common/xstring.h" #include "src/common/assoc_mgr.h" @@ -1707,7 +1708,7 @@ extern int gres_gresid_to_gresname(uint32_t gres_id, char* gres_name, while ((gres_slurmd_conf = (gres_slurmd_conf_t *) list_next(iter))) { if (gres_slurmd_conf->plugin_id != gres_id) continue; - strncpy(gres_name, gres_slurmd_conf->name, gres_name_len); + strlcpy(gres_name, gres_slurmd_conf->name, gres_name_len); found = 1; break; } diff --git a/src/common/hostlist.c b/src/common/hostlist.c index 33fd9a1b9645224acf3be219f6eb80110dbe4f76..c8b3cb7fbc18a094705970d425b2338cfd95e67a 100644 --- a/src/common/hostlist.c +++ b/src/common/hostlist.c @@ -57,6 +57,7 @@ #include "src/common/log.h" #include "src/common/macros.h" #include "src/common/strnatcmp.h" +#include "src/common/strlcpy.h" #include "src/common/timers.h" #include "src/common/working_cluster.h" #include "src/common/xassert.h" @@ -1792,8 +1793,7 @@ _push_range_list(hostlist_t hl, char *prefix, struct _range *range, char *p, *q; char new_prefix[1024], tmp_prefix[1024]; - strncpy(tmp_prefix, prefix, sizeof(tmp_prefix)); - tmp_prefix[sizeof(tmp_prefix) - 1] = '\0'; + strlcpy(tmp_prefix, prefix, sizeof(tmp_prefix)); if (((p = strrchr(tmp_prefix, '[')) != NULL) && ((q = strrchr(p, ']')) != NULL)) { struct _range *prefix_range = NULL; diff --git a/src/common/macros.h b/src/common/macros.h index 2207c21b43c54e13415f1ff843fffac448a42ae8..632d83c261080f94d72b8380105ee96b58acb890 100644 --- a/src/common/macros.h +++ b/src/common/macros.h @@ -48,6 +48,7 @@ #include <stdlib.h> /* for abort() */ #include <string.h> /* for strerror() */ #include "src/common/log.h" /* for error() */ +#include "src/common/strlcpy.h" #ifndef MAX # define MAX(a,b) ((a) > (b) ? (a) : (b)) @@ -266,7 +267,7 @@ do { \ if (strftime(tmp_string, sizeof(tmp_string), format, tm) == 0) \ memset(tmp_string, '#', max); \ tmp_string[max-1] = 0; \ - strncpy(s, tmp_string, max); \ + strlcpy(s, tmp_string, max); \ } \ } while (0) diff --git a/src/common/plugin.c b/src/common/plugin.c index a7447cc44992ec30c74e22a950df712731662144..eb54a1b0b4fa6cdddf2d42975aa038a53228ba3c 100644 --- a/src/common/plugin.c +++ b/src/common/plugin.c @@ -53,6 +53,7 @@ #include "src/common/xmalloc.h" #include "src/common/log.h" #include "src/common/plugrack.h" +#include "src/common/strlcpy.h" #include "src/common/xstring.h" #include "src/common/slurm_protocol_api.h" #include "slurm/slurm_errno.h" @@ -115,7 +116,7 @@ plugin_peek( const char *fq_path, } if ( ( type = dlsym( plug, PLUGIN_TYPE ) ) != NULL ) { if ( plugin_type != NULL ) { - strncpy( plugin_type, type, type_len ); + strlcpy(plugin_type, type, type_len); } } else { dlclose( plug ); diff --git a/src/common/read_config.c b/src/common/read_config.c index fd8373c9ce7392556466d862a633c5c19f836bce..b633a6e0df266c9547b5c3b2afeaffe447cee9a2 100644 --- a/src/common/read_config.c +++ b/src/common/read_config.c @@ -1015,9 +1015,9 @@ int slurm_conf_frontend_array(slurm_conf_frontend_t **ptr_array[]) "NodeName", conf_hashtbl) || (node_count == 0)) fatal("No front end nodes configured"); - strncpy(addresses, node_ptr[0]->addresses, + strlcpy(addresses, node_ptr[0]->addresses, sizeof(addresses)); - strncpy(hostnames, node_ptr[0]->hostnames, + strlcpy(hostnames, node_ptr[0]->hostnames, sizeof(hostnames)); local_front_end.addresses = addresses; local_front_end.frontends = hostnames; diff --git a/src/common/slurm_protocol_socket_implementation.c b/src/common/slurm_protocol_socket_implementation.c index a46fc3700a203f22cde1a08ecfceacc1cd230a20..47e82305d922755fe5d7481e0bb2fb5807548ed8 100644 --- a/src/common/slurm_protocol_socket_implementation.c +++ b/src/common/slurm_protocol_socket_implementation.c @@ -60,6 +60,7 @@ #include "src/common/slurm_protocol_defs.h" #include "src/common/log.h" #include "src/common/fd.h" +#include "src/common/strlcpy.h" #include "src/common/xsignal.h" #include "src/common/xmalloc.h" #include "src/common/util-net.h" @@ -670,11 +671,11 @@ extern void slurm_get_addr (slurm_addr_t *addr, uint16_t *port, char *host, if (he != NULL) { *port = ntohs(addr->sin_port); - strncpy(host, he->h_name, buflen); + strlcpy(host, he->h_name, buflen); } else { error("Lookup failed: %s", host_strerror(h_err)); *port = 0; - strncpy(host, "", buflen); + host[0] = '\0'; } return; } diff --git a/src/plugins/accounting_storage/filetxt/filetxt_jobacct_process.c b/src/plugins/accounting_storage/filetxt/filetxt_jobacct_process.c index a8cc8562c7044c5a15ed3cf5a953a2a8422ddefa..7c328d7fe00c2225c25f82fc3bba028977e25ef8 100644 --- a/src/plugins/accounting_storage/filetxt/filetxt_jobacct_process.c +++ b/src/plugins/accounting_storage/filetxt/filetxt_jobacct_process.c @@ -47,6 +47,7 @@ #include <sys/stat.h> #include "src/common/slurm_xlator.h" +#include "src/common/strlcpy.h" #include "filetxt_jobacct_process.h" #include "src/slurmctld/slurmctld.h" #include "src/slurmdbd/read_config.h" @@ -440,8 +441,7 @@ static char *_prefix_filename(char *path, char *prefix) { } i++; *out = 0; - strncpy(out, path, i); - out[i] = 0; + strlcpy(out, path, i); strcat(out, prefix); strcat(out, path+i); return(out); diff --git a/src/plugins/switch/nrt/nrt.c b/src/plugins/switch/nrt/nrt.c index 8e0f91866072626bd0ab5a844f4b5241eddbf449..700c674ceac476e41b6d205505a76a00d4c3dbe7 100644 --- a/src/plugins/switch/nrt/nrt.c +++ b/src/plugins/switch/nrt/nrt.c @@ -64,6 +64,7 @@ #include "slurm/slurm_errno.h" #include "src/common/slurm_xlator.h" +#include "src/common/strlcpy.h" #include "src/common/read_config.h" #include "src/common/node_conf.h" #include "src/plugins/switch/nrt/nrt_keys.h" @@ -392,7 +393,7 @@ _fill_in_adapter_cache(void) } lid_cache[lid_cache_size].adapter_type = adapter_names. adapter_type; - strncpy(lid_cache[lid_cache_size].adapter_name, + strlcpy(lid_cache[lid_cache_size].adapter_name, adapter_names.adapter_names[j], NRT_MAX_ADAPTER_NAME_LEN); lid_cache_size++; @@ -857,7 +858,7 @@ _alloc_node(slurm_nrt_libstate_t *lp, char *name) sizeof(struct slurm_nrt_adapter)); if (name != NULL) { - strncpy(n->name, name, NRT_HOSTLEN); + strlcpy(n->name, name, NRT_HOSTLEN); if (need_hash_rebuild || (lp->node_count > lp->hash_max)) _hash_rebuild(lp); else @@ -1197,7 +1198,7 @@ _allocate_windows_all(slurm_nrt_jobinfo_t *jp, char *hostname, ib_table = (nrt_ib_task_info_t *) tableinfo[table_inx].table; ib_table += task_id; - strncpy(ib_table->device_name, + strlcpy(ib_table->device_name, adapter->adapter_name, NRT_MAX_DEVICENAME_SIZE); ib_table->base_lid = adapter->lid; @@ -1240,14 +1241,14 @@ _allocate_windows_all(slurm_nrt_jobinfo_t *jp, char *hostname, goto alloc_fail; } - strncpy(tableinfo[table_inx].adapter_name, + strlcpy(tableinfo[table_inx].adapter_name, adapter->adapter_name, NRT_MAX_ADAPTER_NAME_LEN); tableinfo[table_inx].adapter_type = adapter-> adapter_type; tableinfo[table_inx].network_id = adapter-> network_id; - strncpy(tableinfo[table_inx].protocol_name, + strlcpy(tableinfo[table_inx].protocol_name, protocol_table-> protocol_table[context_id]. protocol_name, @@ -1393,7 +1394,7 @@ _allocate_window_single(char *adapter_name, slurm_nrt_jobinfo_t *jp, ib_table = (nrt_ib_task_info_t *) tableinfo[table_inx].table; ib_table += task_id; - strncpy(ib_table->device_name, adapter_name, + strlcpy(ib_table->device_name, adapter_name, NRT_MAX_DEVICENAME_SIZE); ib_table->base_lid = adapter->lid; ib_table->port_id = 1; @@ -1432,12 +1433,12 @@ _allocate_window_single(char *adapter_name, slurm_nrt_jobinfo_t *jp, goto alloc_fail; } - strncpy(tableinfo[table_inx].adapter_name, adapter_name, + strlcpy(tableinfo[table_inx].adapter_name, adapter_name, NRT_MAX_ADAPTER_NAME_LEN); tableinfo[table_inx].adapter_type = adapter-> adapter_type; tableinfo[table_inx].network_id = adapter->network_id; - strncpy(tableinfo[table_inx].protocol_name, + strlcpy(tableinfo[table_inx].protocol_name, protocol_table->protocol_table[context_id]. protocol_name, NRT_MAX_PROTO_NAME_LEN); @@ -2242,7 +2243,7 @@ _get_adapters(slurm_nrt_nodeinfo_t *n) _print_adapter_status(&adapter_status); } adapter_ptr = &n->adapter_list[n->adapter_count]; - strncpy(adapter_ptr->adapter_name, + strlcpy(adapter_ptr->adapter_name, adapter_status.adapter_name, NRT_MAX_ADAPTER_NAME_LEN); adapter_ptr->adapter_type = adapter_status. @@ -2378,7 +2379,7 @@ nrt_build_nodeinfo(slurm_nrt_nodeinfo_t *n, char *name) xassert(n->magic == NRT_NODEINFO_MAGIC); xassert(name); - strncpy(n->name, name, NRT_HOSTLEN); + strlcpy(n->name, name, NRT_HOSTLEN); slurm_mutex_lock(&global_lock); err = _get_adapters(n); slurm_mutex_unlock(&global_lock); @@ -2452,13 +2453,13 @@ _copy_node(slurm_nrt_nodeinfo_t *dest, slurm_nrt_nodeinfo_t *src) _print_nodeinfo(src); } - strncpy(dest->name, src->name, NRT_HOSTLEN); + strlcpy(dest->name, src->name, NRT_HOSTLEN); dest->node_number = src->node_number; dest->adapter_count = src->adapter_count; for (i = 0; i < dest->adapter_count; i++) { sa = src->adapter_list + i; da = dest->adapter_list +i; - strncpy(da->adapter_name, sa->adapter_name, + strlcpy(da->adapter_name, sa->adapter_name, NRT_MAX_ADAPTER_NAME_LEN); da->adapter_type = sa->adapter_type; da->cau_indexes_avail = sa->cau_indexes_avail; @@ -2620,7 +2621,7 @@ _fake_unpack_adapters(Buf buf, slurm_nrt_nodeinfo_t *n, sizeof(slurm_nrt_adapter_t) * n->adapter_count); tmp_a = n->adapter_list + j; - strncpy(tmp_a->adapter_name, name_ptr, + strlcpy(tmp_a->adapter_name, name_ptr, NRT_MAX_ADAPTER_NAME_LEN); tmp_a->adapter_type = adapter_type; /* tmp_a->block_count = 0 */ @@ -2969,7 +2970,7 @@ static nrt_protocol_table_t *_get_protocol_table(char *protocol) if ((i >= protocol_table->protocol_table_cnt) && (i < NRT_MAX_PROTO_CNT)) { /* Need to add new protocol type */ - strncpy(protocol_table->protocol_table[i].protocol_name, + strlcpy(protocol_table->protocol_table[i].protocol_name, token, NRT_MAX_PROTO_NAME_LEN); protocol_table->protocol_table_cnt++; } @@ -3856,12 +3857,12 @@ nrt_load_table(slurm_nrt_jobinfo_t *jp, int uid, int pid, char *job_name) sep++; else sep = job_name; - strncpy(table_info.job_name, sep, + strlcpy(table_info.job_name, sep, NRT_MAX_JOB_NAME_LEN); } else { table_info.job_name[0] = '\0'; } - strncpy(table_info.protocol_name, + strlcpy(table_info.protocol_name, jp->tableinfo[i].protocol_name, NRT_MAX_PROTO_NAME_LEN); table_info.use_bulk_transfer = jp->bulk_xfer; diff --git a/src/plugins/switch/nrt/switch_nrt.c b/src/plugins/switch/nrt/switch_nrt.c index 5e91470a162e94a13e864a59cdd797b700ac2a34..1a728d4bb61aac98e4352d23531e97aecc59526d 100644 --- a/src/plugins/switch/nrt/switch_nrt.c +++ b/src/plugins/switch/nrt/switch_nrt.c @@ -49,6 +49,7 @@ #include "slurm/slurm_errno.h" #include "src/common/slurm_xlator.h" #include "src/common/macros.h" +#include "src/common/strlcpy.h" #include "src/plugins/switch/nrt/slurm_nrt.h" #define NRT_BUF_SIZE 4096 @@ -1032,7 +1033,7 @@ static void *_state_save_thread(void *arg) { char *dir_name = (char *)arg; - strncpy(local_dir_path, dir_name, sizeof(local_dir_path)); + strlcpy(local_dir_path, dir_name, sizeof(local_dir_path)); xfree(dir_name); while (1) { diff --git a/src/plugins/task/affinity/dist_tasks.c b/src/plugins/task/affinity/dist_tasks.c index 92132e166a8587d0ad779f83b07db590c7dbe17d..cf6226062509bbb28c00d7ecfd290162e2129039 100644 --- a/src/plugins/task/affinity/dist_tasks.c +++ b/src/plugins/task/affinity/dist_tasks.c @@ -41,6 +41,7 @@ #include "src/common/slurm_cred.h" #include "src/common/slurm_protocol_api.h" #include "src/common/slurm_resource_info.h" +#include "src/common/strlcpy.h" #include "src/common/xmalloc.h" #include "src/slurmd/slurmd/slurmd.h" @@ -1327,9 +1328,8 @@ static void _lllp_generate_cpu_bind(launch_tasks_request_msg_t *req, if (masks_len > 0) masks_str[masks_len-1]=','; - strncpy(&masks_str[masks_len], str, curlen); + strlcpy(&masks_str[masks_len], str, curlen); masks_len += curlen; - xassert(masks_str[masks_len] == '\0'); xfree(str); } diff --git a/src/sacctmgr/file_functions.c b/src/sacctmgr/file_functions.c index a68c93eb1f4b9bf4b159d43dd039fa5b0b4baabf..1a663485dba931db95e2ccd654caa88f62c10c8e 100644 --- a/src/sacctmgr/file_functions.c +++ b/src/sacctmgr/file_functions.c @@ -39,6 +39,7 @@ \*****************************************************************************/ #include "src/sacctmgr/sacctmgr.h" +#include "src/common/strlcpy.h" #include "src/common/uid.h" typedef struct { @@ -1686,7 +1687,7 @@ extern void load_sacctmgr_cfg_file (int argc, char **argv) if (line[i-1] == ' ') i--; if (i<sizeof(object)) - strncpy(object, line, i); + strlcpy(object, line, i); break; } } diff --git a/src/sacctmgr/sacctmgr.c b/src/sacctmgr/sacctmgr.c index 24eaa409944017d988f25d846e40b73300750074..04902a5140b94aeb17601fb434a35dba9a441796 100644 --- a/src/sacctmgr/sacctmgr.c +++ b/src/sacctmgr/sacctmgr.c @@ -44,6 +44,7 @@ #include "src/sacctmgr/sacctmgr.h" #include "src/common/xsignal.h" #include "src/common/proc_args.h" +#include "src/common/strlcpy.h" #define BUFFER_SIZE 4096 @@ -278,7 +279,7 @@ static char *_getline(const char *prompt) line = malloc(len * sizeof(char)); if (!line) return NULL; - return strncpy(line, buf, len); + return strlcpy(line, buf, len); } #endif diff --git a/src/scontrol/scontrol.c b/src/scontrol/scontrol.c index 9f77c627472bd0023ca4748f299216bb6640e0a8..0334c080fe08fe7d7117a8a21604421c570f265d 100644 --- a/src/scontrol/scontrol.c +++ b/src/scontrol/scontrol.c @@ -44,6 +44,7 @@ #include "scontrol.h" #include "src/plugins/select/bluegene/bg_enums.h" #include "src/common/proc_args.h" +#include "src/common/strlcpy.h" #include "src/common/uid.h" #define OPT_LONG_HIDE 0x102 @@ -303,7 +304,7 @@ static char *_getline(const char *prompt) line = malloc(len * sizeof(char)); if (!line) return NULL; - return strncpy(line, buf, len); + return strlcpy(line, buf, len); } #endif diff --git a/src/slurmctld/reservation.c b/src/slurmctld/reservation.c index 67d633ed4b9c8077550c0320592d135dc6d947df..9943e36e30fe0d757b4bef45487a42525113ece6 100644 --- a/src/slurmctld/reservation.c +++ b/src/slurmctld/reservation.c @@ -64,6 +64,7 @@ #include "src/common/parse_time.h" #include "src/common/slurm_accounting_storage.h" #include "src/common/slurm_time.h" +#include "src/common/strlcpy.h" #include "src/common/uid.h" #include "src/common/xassert.h" #include "src/common/xmalloc.h" @@ -573,7 +574,7 @@ static void _generate_resv_name(resv_desc_msg_t *resv_ptr) else len = strlen(key); name = xmalloc(len + 16); - strncpy(name, key, len); + strlcpy(name, key, len); xstrfmtcat(name, "_%d", top_suffix); len++; diff --git a/src/slurmd/slurmstepd/mgr.c b/src/slurmd/slurmstepd/mgr.c index b423960a0028afdd7512adb0cab943890ca18480..57c3dedd9bba98a44311b0af20608d9b29677e10 100644 --- a/src/slurmd/slurmstepd/mgr.c +++ b/src/slurmd/slurmstepd/mgr.c @@ -85,6 +85,7 @@ #include "src/common/slurm_cred.h" #include "src/common/slurm_jobacct_gather.h" #include "src/common/slurm_mpi.h" +#include "src/common/strlcpy.h" #include "src/common/switch.h" #include "src/common/util-net.h" #include "src/common/xmalloc.h" @@ -2434,7 +2435,7 @@ _drop_privileges(stepd_step_rec_t *job, bool do_setuid, if (!getcwd (ps->saved_cwd, sizeof (ps->saved_cwd))) { error ("Unable to get current working directory: %m"); - strncpy (ps->saved_cwd, "/tmp", sizeof (ps->saved_cwd)); + strlcpy(ps->saved_cwd, "/tmp", sizeof(ps->saved_cwd)); } #ifdef HAVE_NATIVE_CRAY diff --git a/src/sreport/sreport.c b/src/sreport/sreport.c index 9111207088fac6b7b6d24741e5b0476d237a5a01..7c7bb0bcd7ea2dac8448bcb093fd6eb39ed713c7 100644 --- a/src/sreport/sreport.c +++ b/src/sreport/sreport.c @@ -47,6 +47,7 @@ #include "src/sreport/user_reports.h" #include "src/common/xsignal.h" #include "src/common/proc_args.h" +#include "src/common/strlcpy.h" #define BUFFER_SIZE 4096 #define OPT_LONG_LOCAL 0x101 @@ -379,7 +380,7 @@ static char *_getline(const char *prompt) line = malloc(len * sizeof(char)); if (!line) return NULL; - return strncpy(line, buf, len); + return strlcpy(line, buf, len); } #endif