[PATCH v2] app/testpmd: fix flex item link parsing
Maayan Kashani
mkashani at nvidia.com
Sun Nov 16 13:14:37 CET 2025
The flex_link_item_parse function was using FLEX_MAX_FLOW_PATTERN_LENGTH
for all memcpy operations regardless of the actual flow item type. This
could lead to copying incorrect amounts of data.
This patch adds a switch statement to determine the correct size based
on the actual flow item type (IPv4, IPv6, UDP, TCP) and uses that size
for the memcpy operations on spec, mask, and last fields.
Also adds validation to reject unsupported item types.
Fixes: 59f3a8acbcdb ("app/testpmd: add flex item commands")
Cc: stable at dpdk.org
Signed-off-by: Maayan Kashani <mkashani at nvidia.com>
---
app/test-pmd/cmd_flex_item.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/app/test-pmd/cmd_flex_item.c b/app/test-pmd/cmd_flex_item.c
index e6e1cefeb3d..af6c087feba 100644
--- a/app/test-pmd/cmd_flex_item.c
+++ b/app/test-pmd/cmd_flex_item.c
@@ -143,21 +143,22 @@ flex_link_item_parse(const char *src, struct rte_flow_item *item)
if (ret)
return ret;
item->type = pattern->type;
- if (pattern->spec) {
+ ret = rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_MASK, NULL, 0, item, NULL);
+ if ((ret > 0) && pattern->spec) {
ptr = (void *)(uintptr_t)item->spec;
- memcpy(ptr, pattern->spec, FLEX_MAX_FLOW_PATTERN_LENGTH);
+ memcpy(ptr, pattern->spec, ret);
} else {
item->spec = NULL;
}
- if (pattern->mask) {
+ if ((ret > 0) && pattern->mask) {
ptr = (void *)(uintptr_t)item->mask;
- memcpy(ptr, pattern->mask, FLEX_MAX_FLOW_PATTERN_LENGTH);
+ memcpy(ptr, pattern->mask, ret);
} else {
item->mask = NULL;
}
- if (pattern->last) {
+ if ((ret > 0) && pattern->last) {
ptr = (void *)(uintptr_t)item->last;
- memcpy(ptr, pattern->last, FLEX_MAX_FLOW_PATTERN_LENGTH);
+ memcpy(ptr, pattern->last, ret);
} else {
item->last = NULL;
}
--
2.21.0
More information about the dev
mailing list