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")
Cc: [email protected]

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(-)

diff --git a/app/test-crypto-perf/cperf_options_parsing.c 
b/app/test-crypto-perf/cperf_options_parsing.c
index 14e731586b..0951293adb 100644
--- a/app/test-crypto-perf/cperf_options_parsing.c
+++ b/app/test-crypto-perf/cperf_options_parsing.c
@@ -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;
 
diff --git a/app/test-dma-perf/main.c b/app/test-dma-perf/main.c
index 4249dcfd3d..13bf07a764 100644
--- a/app/test-dma-perf/main.c
+++ b/app/test-dma-perf/main.c
@@ -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;
 
diff --git a/app/test-eventdev/evt_options.c b/app/test-eventdev/evt_options.c
index 0e70c971eb..1da0aba386 100644
--- a/app/test-eventdev/evt_options.c
+++ b/app/test-eventdev/evt_options.c
@@ -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;
diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 67f200f2e3..465396d2e5 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -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;
diff --git a/app/test-regex/main.c b/app/test-regex/main.c
index acb834a8b4..81719f2e04 100644
--- a/app/test-regex/main.c
+++ b/app/test-regex/main.c
@@ -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);
-- 
2.53.0

Reply via email to