[PATCH v2 2/7] examples/vdpa: fix format overflow warning

Bruce Richardson bruce.richardson at intel.com
Fri Nov 14 16:59:59 CET 2025


On Tue, Nov 11, 2025 at 02:17:19PM -0800, Stephen Hemminger wrote:
> 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"))

nit: sizeof("1024") == 5, because of the \0.

> to avoid possible format overflow
> 
> Fixes: 38f8ab0bbc8d ("vhost: make vDPA framework bus agnostic")
> Cc: maxime.coquelin at redhat.com
> Cc: stable at dpdk.org
> 
> Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>

I assume this was found by enabling compiler warnings. It would be good to
include the actual warning message in the commit log, given that the patch
doesn't actually modify the line at which the overflow occurs.

Acked-by: Bruce Richardson <bruce.richardson at intel.com>


> ---
>  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))

We have RTE_STR() and _RTE_STR() in rte_common.h

>  #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));

I realise that the rte_strscpy function is what was here before, but given
that we are not checking the return value, there is no reason to choose the
dpdk-only strscpy function over the more-standard strlcpy.

>  				printf("iface %s\n", iface);
>  			}
>  			if (!strcmp(long_option[idx].name, "interactive")) {
> -- 
> 2.51.0
> 


More information about the dev mailing list