From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: "Bruce Richardson" <bruce.richardson@intel.com>,
stable@dpdk.org, "Kai Ji" <kai.ji@intel.com>,
"Cheng Jiang" <honest.jiang@foxmail.com>,
"Chengwen Feng" <fengchengwen@huawei.com>,
"Jerin Jacob" <jerinj@marvell.com>, "Ori Kam" <orika@nvidia.com>,
"Aman Singh" <aman.deep.singh@intel.com>,
"Michal Kobylinski" <michalx.kobylinski@intel.com>,
"Piotr Azarewicz" <piotr.azarewicz@intel.com>,
"Marcin Kerlin" <marcinx.kerlin@intel.com>,
"Slawomir Mrozowicz" <slawomirx.mrozowicz@intel.com>,
"Declan Doherty" <declan.doherty@intel.com>,
"Aleksander Gajewski" <aleksanderx.gajewski@intel.com>,
"Pablo de Lara" <pablo.de.lara.guarch@intel.com>,
"Guduri Prathyusha" <gprathyusha@caviumnetworks.com>,
"Harry van Haaren" <harry.van.haaren@intel.com>,
"Morten Brørup" <mb@smartsharesystems.com>,
"Jiayu Hu" <hujiayu.hu@foxmail.com>,
"Yuan Wang" <yuanx.wang@intel.com>,
"Anoob Joseph" <anoobj@marvell.com>,
"Xiaoyu Min" <jackmin@nvidia.com>,
"Xueming Li" <xuemingl@nvidia.com>,
"Yuval Avnery" <yuvalav@nvidia.com>
Subject: [PATCH] app: remove use of strncpy
Date: Tue, 23 Jun 2026 15:50:27 +0100 [thread overview]
Message-ID: <20260623145028.711712-1-bruce.richardson@intel.com> (raw)
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: stable@dpdk.org
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
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 other threads:[~2026-06-23 14:51 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260623145028.711712-1-bruce.richardson@intel.com \
--to=bruce.richardson@intel.com \
--cc=aleksanderx.gajewski@intel.com \
--cc=aman.deep.singh@intel.com \
--cc=anoobj@marvell.com \
--cc=declan.doherty@intel.com \
--cc=dev@dpdk.org \
--cc=fengchengwen@huawei.com \
--cc=gprathyusha@caviumnetworks.com \
--cc=harry.van.haaren@intel.com \
--cc=honest.jiang@foxmail.com \
--cc=hujiayu.hu@foxmail.com \
--cc=jackmin@nvidia.com \
--cc=jerinj@marvell.com \
--cc=kai.ji@intel.com \
--cc=marcinx.kerlin@intel.com \
--cc=mb@smartsharesystems.com \
--cc=michalx.kobylinski@intel.com \
--cc=orika@nvidia.com \
--cc=pablo.de.lara.guarch@intel.com \
--cc=piotr.azarewicz@intel.com \
--cc=slawomirx.mrozowicz@intel.com \
--cc=stable@dpdk.org \
--cc=xuemingl@nvidia.com \
--cc=yuanx.wang@intel.com \
--cc=yuvalav@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox