From 2acb052cc6ba86ee0567cd67bef04e470b9a5bf3 Mon Sep 17 00:00:00 2001 From: Tim Wickberg <tim@schedmd.com> Date: Thu, 3 Aug 2017 14:58:13 -0600 Subject: [PATCH] Replace strncpy calls with strlcpy. Ensure proper termination in places that were otherwise missing it, and remove some awkward termination handling in other locations. --- src/api/job_info.c | 3 +- src/api/slurm_pmi.c | 8 ++--- src/common/cpu_frequency.c | 16 ++++----- src/common/env.c | 7 ++-- src/common/gres.c | 3 +- src/common/hostlist.c | 4 +-- src/common/macros.h | 3 +- src/common/plugin.c | 3 +- src/common/read_config.c | 4 +-- .../slurm_protocol_socket_implementation.c | 5 +-- .../filetxt/filetxt_jobacct_process.c | 4 +-- src/plugins/switch/nrt/nrt.c | 33 ++++++++++--------- src/plugins/switch/nrt/switch_nrt.c | 3 +- src/plugins/task/affinity/dist_tasks.c | 4 +-- src/sacctmgr/file_functions.c | 3 +- src/sacctmgr/sacctmgr.c | 3 +- src/scontrol/scontrol.c | 3 +- src/slurmctld/reservation.c | 3 +- src/slurmd/slurmstepd/mgr.c | 3 +- src/sreport/sreport.c | 3 +- 20 files changed, 64 insertions(+), 54 deletions(-) diff --git a/src/api/job_info.c b/src/api/job_info.c index 69053c5d9d5..df35e9dd39e 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 31dcaaaae6e..a8ad173db76 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 cc5aaf7715d..a7c6f58c41f 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 c9d2ce673ac..ddeeccf1749 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 ab767d3ca97..1cbb9067804 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 33fd9a1b964..c8b3cb7fbc1 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 2207c21b43c..632d83c2610 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 a7447cc4499..eb54a1b0b4f 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 fd8373c9ce7..b633a6e0df2 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 a46fc3700a2..47e82305d92 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 a8cc8562c70..7c328d7fe00 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 8e0f9186607..700c674ceac 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 5e91470a162..1a728d4bb61 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 92132e166a8..cf622606250 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 a68c93eb1f4..1a663485dba 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 24eaa409944..04902a5140b 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 9f77c627472..0334c080fe0 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 67d633ed4b9..9943e36e30f 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 b423960a002..57c3dedd9bb 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 9111207088f..7c7bb0bcd7e 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 -- GitLab