The ifname is limited to 128 characters, but it would allow up
to 128 characters as prefix then could overflow creating ifname.

Change to limit path prefix to 124 (128 - sizeof("1024"))
to avoid possible format overflow

Fixes: 38f8ab0bbc8d ("vhost: make vDPA framework bus agnostic")
Cc: [email protected]
Cc: [email protected]

Signed-off-by: Stephen Hemminger <[email protected]>
---
 examples/vdpa/main.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/examples/vdpa/main.c b/examples/vdpa/main.c
index 289db26498..7fd0e55b20 100644
--- a/examples/vdpa/main.c
+++ b/examples/vdpa/main.c
@@ -22,6 +22,8 @@
 
 #define MAX_PATH_LEN 128
 #define MAX_VDPA_SAMPLE_PORTS 1024
+#define stringify(x) (#x)
+#define MAX_VDPA_STR_LEN sizeof(stringify(MAX_VDPA_SAMPLE_PORTS))
 #define RTE_LOGTYPE_VDPA RTE_LOGTYPE_USER1
 
 struct vdpa_port {
@@ -36,7 +38,7 @@ struct vdpa_port {
 
 static struct vdpa_port vports[MAX_VDPA_SAMPLE_PORTS];
 
-static char iface[MAX_PATH_LEN];
+static char iface[MAX_PATH_LEN - MAX_VDPA_STR_LEN];
 static int devcnt;
 static int interactive;
 static int client_mode;
@@ -74,9 +76,8 @@ parse_args(int argc, char **argv)
                        break;
                /* long options */
                case 0:
-                       if (strncmp(long_option[idx].name, "iface",
-                                               MAX_PATH_LEN) == 0) {
-                               rte_strscpy(iface, optarg, MAX_PATH_LEN);
+                       if (!strcmp(long_option[idx].name, "iface")) {
+                               rte_strscpy(iface, optarg, sizeof(iface));
                                printf("iface %s\n", iface);
                        }
                        if (!strcmp(long_option[idx].name, "interactive")) {
-- 
2.51.0

Reply via email to