[PATCH v11 6/6] test: fix format overflow in cryptodev test

Stephen Hemminger
2026-01-17T02:39:02Z

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")
Cc: stable@dpdk.org

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
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