DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	Akhil Goyal <gakhil@marvell.com>,
	Fan Zhang <fanzhang.oss@gmail.com>,
	Hemant Agrawal <hemant.agrawal@nxp.com>,
	Ciara Power <ciara.power@intel.com>,
	Declan Doherty <declan.doherty@intel.com>
Subject: [PATCH v4 7/8] test: fix format overflow in cryptodev test
Date: Thu, 20 Nov 2025 08:55:35 -0800	[thread overview]
Message-ID: <20251120165713.120238-8-stephen@networkplumber.org> (raw)
In-Reply-To: <20251120165713.120238-1-stephen@networkplumber.org>

The vdev args buffer could in theory get truncated if there were
lots of sockets or lcores. Handle that by checking return value
of snprintf.

Fixes: 8bfdd8a7f0f1 ("test/crypto: refactor to use sub test suites")

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/test/test_cryptodev.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 9bdd357727..bd6a2d3fa6 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -17713,8 +17713,16 @@ scheduler_testsuite_setup(void)
 		RTE_LCORE_FOREACH_WORKER(i) {
 			if (worker_core_count > 1)
 				break;
-			snprintf(vdev_args, sizeof(vdev_args),
-					"%s%d", temp_str, i);
+			ret = snprintf(vdev_args, sizeof(vdev_args),
+					   "%s%d", temp_str, i);
+
+			/* If too many args the result will have been truncated */
+			if (ret >= VDEV_ARGS_SIZE) {
+				RTE_LOG(ERR, USER1,
+					"Cryptodev scheduler test vdev arg size exceeded\n");
+				return TEST_FAILED;
+			}
+
 			strcpy(temp_str, vdev_args);
 			strlcat(temp_str, ";", sizeof(temp_str));
 			worker_core_count++;
@@ -17728,8 +17736,14 @@ scheduler_testsuite_setup(void)
 			return TEST_FAILED;
 		}
 		strcpy(temp_str, vdev_args);
-		snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d",
-				temp_str, socket_id);
+		ret = snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d",
+			       temp_str, socket_id);
+		if (ret >= VDEV_ARGS_SIZE) {
+			RTE_LOG(ERR, USER1,
+				"Cryptodev scheduler test vdev arg size exceeded\n");
+			return TEST_FAILED;
+		}
+
 		RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args);
 		nb_devs = rte_cryptodev_device_count_by_driver(
 				rte_cryptodev_driver_id_get(
-- 
2.51.0


  parent reply	other threads:[~2025-11-20 16:58 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <0251115193409.99740-1-stephen@networkplumber.org>
2025-11-20 16:55 ` [PATCH v4 0/8] tests: enable format truncation checks Stephen Hemminger
2025-11-20 16:55   ` [PATCH v4 1/8] test: increase size of memzone name Stephen Hemminger
2025-11-20 16:55   ` [PATCH v4 2/8] test: refactor file prefix arg handling Stephen Hemminger
2025-11-20 16:55   ` [PATCH v4 3/8] test: avoid overflowing huge directory path Stephen Hemminger
2025-11-21 12:04     ` Burakov, Anatoly
2025-11-20 16:55   ` [PATCH v4 4/8] test: use unit test runner for eal flags Stephen Hemminger
2025-11-21 12:06     ` Burakov, Anatoly
2025-11-20 16:55   ` [PATCH v4 5/8] test: fix format overflow warning in ACL test Stephen Hemminger
2025-11-21 12:06     ` Burakov, Anatoly
2025-11-20 16:55   ` [PATCH v4 6/8] test: fix impossible format-truncation in cfgfiles Stephen Hemminger
2025-11-21 12:09     ` Burakov, Anatoly
2025-11-20 16:55   ` Stephen Hemminger [this message]
2025-11-21 12:08     ` [PATCH v4 7/8] test: fix format overflow in cryptodev test Burakov, Anatoly
2025-11-20 16:55   ` [PATCH v4 8/8] test: re-enable format-truncation warnings Stephen Hemminger

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=20251120165713.120238-8-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=ciara.power@intel.com \
    --cc=declan.doherty@intel.com \
    --cc=dev@dpdk.org \
    --cc=fanzhang.oss@gmail.com \
    --cc=gakhil@marvell.com \
    --cc=hemant.agrawal@nxp.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;
as well as URLs for NNTP newsgroup(s).