devargs: fix devargs truncation when format string is used

Message ID 1531898610-19654-1-git-send-email-arybchenko@solarflare.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series devargs: fix devargs truncation when format string is used |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Andrew Rybchenko July 18, 2018, 7:23 a.m. UTC
  Space for string terminating NUL character should be provided to
snprintf() to avoid the last symbol truncation.

Fixes: a23bc2c4e01b ("devargs: add non-variadic parsing function")

Reported-by: Ivan Malov <ivan.malov@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
---
 lib/librte_eal/common/eal_common_devargs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Gaëtan Rivet July 18, 2018, 8:42 a.m. UTC | #1
Hi,

On Wed, Jul 18, 2018 at 08:23:30AM +0100, Andrew Rybchenko wrote:
> Space for string terminating NUL character should be provided to
> snprintf() to avoid the last symbol truncation.
> 
> Fixes: a23bc2c4e01b ("devargs: add non-variadic parsing function")
> 
> Reported-by: Ivan Malov <ivan.malov@oktetlabs.ru>
> Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Acked-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> ---
>  lib/librte_eal/common/eal_common_devargs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
> index a22a2002e..5ec688aab 100644
> --- a/lib/librte_eal/common/eal_common_devargs.c
> +++ b/lib/librte_eal/common/eal_common_devargs.c
> @@ -285,7 +285,7 @@ rte_devargs_parsef(struct rte_devargs *da, const char *format, ...)
>  	}
>  
>  	va_start(ap, format);
> -	vsnprintf(dev, len, format, ap);
> +	vsnprintf(dev, len + 1, format, ap);

Indeed, thanks for reporting and fixing.

>  	va_end(ap);
>  
>  	return rte_devargs_parse(da, dev);
> -- 
> 2.17.1
>
  
Thomas Monjalon July 20, 2018, 9:18 a.m. UTC | #2
18/07/2018 10:42, Gaëtan Rivet:
> Hi,
> 
> On Wed, Jul 18, 2018 at 08:23:30AM +0100, Andrew Rybchenko wrote:
> > Space for string terminating NUL character should be provided to
> > snprintf() to avoid the last symbol truncation.
> > 
> > Fixes: a23bc2c4e01b ("devargs: add non-variadic parsing function")
> > 
> > Reported-by: Ivan Malov <ivan.malov@oktetlabs.ru>
> > Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
> Acked-by: Gaetan Rivet <gaetan.rivet@6wind.com>

Applied, thanks
  

Patch

diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
index a22a2002e..5ec688aab 100644
--- a/lib/librte_eal/common/eal_common_devargs.c
+++ b/lib/librte_eal/common/eal_common_devargs.c
@@ -285,7 +285,7 @@  rte_devargs_parsef(struct rte_devargs *da, const char *format, ...)
 	}
 
 	va_start(ap, format);
-	vsnprintf(dev, len, format, ap);
+	vsnprintf(dev, len + 1, format, ap);
 	va_end(ap);
 
 	return rte_devargs_parse(da, dev);