app/testpmd: fix copy of dynamic flag name
authorOri Kam <orika@mellanox.com>
Tue, 4 Feb 2020 13:39:46 +0000 (13:39 +0000)
committerFerruh Yigit <ferruh.yigit@intel.com>
Wed, 5 Feb 2020 08:51:21 +0000 (09:51 +0100)
When working with testpmd and setting the dynflag name, we copy the
name given by the cmd to the dynflag name.

The issue is that the size of the dynflag name is smaller then the
string used by testpmd.

This commit solves this issue by checking that the length of the requested
flag name is not too long.

Coverity issue: 353610
Fixes: b57b66a97ebf ("app/testpmd: support mbuf dynamic flag")

Signed-off-by: Ori Kam <orika@mellanox.com>
Acked-by: Bernard Iremonger <bernard.iremonger@intel.com>
app/test-pmd/cmdline.c

index ff9c7b9..3126548 100644 (file)
@@ -18866,14 +18866,18 @@ cmd_config_dynf_specific_parsed(void *parsed_result,
                return;
        flag = rte_mbuf_dynflag_lookup(res->name, NULL);
        if (flag <= 0) {
-               strcpy(desc_flag.name, res->name);
+               if (strlcpy(desc_flag.name, res->name,
+                           RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
+                       printf("Flag name too long\n");
+                       return;
+               }
                desc_flag.flags = 0;
                flag = rte_mbuf_dynflag_register(&desc_flag);
                if (flag < 0) {
                        printf("Can't register flag\n");
                        return;
                }
-               strcpy(dynf_names[flag], res->name);
+               strcpy(dynf_names[flag], desc_flag.name);
        }
        old_port_flags = ports[res->port_id].mbuf_dynf;
        if (!strcmp(res->value, "set")) {