app: remove use of strncpy
PATCH 1/1 app: remove use of strncpy
Use of strncpy is not recommended, so replace it with strlcpy or memcpy as appropriate.
Fixes f8be1786b1b8 ("app/crypto-perf: introduce performance test application")
Fixes 8ecd4048ba5d ("app/crypto-perf: fix string not null terminated")
Fixes 0add6c27cd7c ("app/testeventdev: define the test options")
Fixes 623dc9364dc6 ("app/dma-perf: introduce DMA performance test")
Fixes 1e8a4e97b057 ("app/testpmd: add flow dump command")
Fixes de06137cb295 ("app/regex: add RegEx test application")
Signed-off-by Bruce Richardson <[email protected]>
--- app/test-crypto-perf/cperf_options_parsing.c | 5 ++--- app/test-dma-perf/main.c | 2 +- app/test-eventdev/evt_options.c | 2 +- app/test-pmd/cmdline_flow.c | 2 +- app/test-regex/main.c | 9 ++------- 5 files changed, 7 insertions(+), 13 deletions(-)
app/test-crypto-perf/cperf_options_parsing.c +2 -3
@@ -481,8 +481,7 @@ parse_device_type(struct cperf_options *opts, const char *arg)if (strlen (arg) > (sizeof (opts->device_type) -1 ))return -1 ; -strncpy (opts->device_type, arg,sizeof (opts->device_type) -1 ); - *(opts->device_type +sizeof (opts->device_type) -1 ) ='\0' ; +strlcpy (opts->device_type, arg,sizeof (opts->device_type));return 0 ; }
@@ -1125,7 +1124,7 @@ cperf_options_default(struct cperf_options *opts) opts->segment_sz =0 ; opts->imix_distribution_count =0 ; -strncpy (opts->device_type,"crypto_aesni_mb" , +strlcpy (opts->device_type,"crypto_aesni_mb" ,sizeof (opts->device_type)); opts->nb_qps =1 ;
app/test-dma-perf/main.c +1 -1
@@ -220,7 +220,7 @@ parse_entry(const char *value, struct test_configure_entry *entry)int args_nr =-1 ;int ret; -strncpy (input, value,254 ); +strlcpy (input, value,sizeof (input));if (*input =='\0' ) goto out;
app/test-eventdev/evt_options.c +1 -1
@@ -23,7 +23,7 @@ evt_options_default(struct evt_options *opt)memset (opt,0 ,sizeof (*opt)); opt->verbose_level =1 ;/* Enable minimal prints */ opt->dev_id =0 ; -strncpy (opt->test_name,"order_queue" ,EVT_TEST_NAME_MAX_LEN ); +strlcpy (opt->test_name,"order_queue" ,sizeof (opt->test_name)); opt->nb_flows =1024 ; opt->socket_id =SOCKET_ID_ANY ; opt->pool_sz =16 *1024 ;
app/test-pmd/cmdline_flow.c +1 -1
@@ -11910,7 +11910,7 @@ parse_string0(struct context *ctx, const struct token *token __rte_unused,if (!ctx->object)return len; buf = (uint8_t *)ctx->object + arg_data->offset; -strncpy (buf, str, len); +memcpy (buf, str, len);if (ctx->objmask)memset ((uint8_t *)ctx->objmask + arg_data->offset,0xff , len);return len;
app/test-regex/main.c +2 -7
@@ -103,7 +103,6 @@ args_parse(int argc, char **argv, char *rules_file, char *data_file,char **argvopt;int opt;int opt_idx; -size_t len;static struct option lgopts[] = { {"help" ,0 ,0 ,ARG_HELP },/* Rules database file to load. */
@@ -133,20 +132,16 @@ args_parse(int argc, char **argv, char *rules_file, char *data_file, lgopts, &opt_idx)) != EOF) {switch (opt) {case ARG_RULES_FILE_NAME : - len =strnlen (optarg,MAX_FILE_NAME -1 ); -if (len ==MAX_FILE_NAME ) +if (strlcpy (rules_file, optarg,MAX_FILE_NAME ) >=MAX_FILE_NAME )rte_exit (EXIT_FAILURE ,"Rule file name to long max %d\n" ,MAX_FILE_NAME -1 ); -strncpy (rules_file, optarg,MAX_FILE_NAME -1 );break ;case ARG_DATA_FILE_NAME : - len =strnlen (optarg,MAX_FILE_NAME -1 ); -if (len ==MAX_FILE_NAME ) +if (strlcpy (data_file, optarg,MAX_FILE_NAME ) >=MAX_FILE_NAME )rte_exit (EXIT_FAILURE ,"Data file name to long max %d\n" ,MAX_FILE_NAME -1 ); -strncpy (data_file, optarg,MAX_FILE_NAME -1 );break ;case ARG_NUM_OF_JOBS : *nb_jobs =atoi (optarg);
Signature · 1 line
2.53.0
Thomas Monjalon
Applied23/06/2026 16:50, Bruce Richardson:
Quoted 11 lines
Use of strncpy is not recommended, so replace it with strlcpy or memcpy as appropriate.
Fixes f8be1786b1b8 ("app/crypto-perf: introduce performance test application")Fixes 8ecd4048ba5d ("app/crypto-perf: fix string not null terminated")Fixes 0add6c27cd7c ("app/testeventdev: define the test options")Fixes 623dc9364dc6 ("app/dma-perf: introduce DMA performance test")Fixes 1e8a4e97b057 ("app/testpmd: add flow dump command")Fixes de06137cb295 ("app/regex: add RegEx test application")
Quoted 1 line
Signed-off-by Bruce Richardson <[email protected]>
Applied, thanks.