[2/6] net/tap: allow full length names

Message ID 20190111180659.5972-3-stephen@networkplumber.org (mailing list archive)
State Superseded, archived
Headers
Series net/tap: fixes and cleanups |

Checks

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

Commit Message

Stephen Hemminger Jan. 11, 2019, 6:06 p.m. UTC
  The code for set_interface_name was incorrectly assuming that
space for null byte was necessary with snprintf/strlcpy.

Fixes: 02f96a0a82d1 ("net/tap: add TUN/TAP device PMD")
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/tap/rte_eth_tap.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Comments

Wiles, Keith Jan. 11, 2019, 7:32 p.m. UTC | #1
> On Jan 11, 2019, at 12:06 PM, Stephen Hemminger <stephen@networkplumber.org> wrote:
> 
> The code for set_interface_name was incorrectly assuming that
> space for null byte was necessary with snprintf/strlcpy.
> 
> Fixes: 02f96a0a82d1 ("net/tap: add TUN/TAP device PMD")
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
> drivers/net/tap/rte_eth_tap.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
> index 1c00681ba0eb..d7f77d664502 100644
> --- a/drivers/net/tap/rte_eth_tap.c
> +++ b/drivers/net/tap/rte_eth_tap.c
> @@ -1892,10 +1892,10 @@ set_interface_name(const char *key __rte_unused,
> 	char *name = (char *)extra_args;
> 
> 	if (value)
> -		strlcpy(name, value, RTE_ETH_NAME_MAX_LEN - 1);
> +		strlcpy(name, value, RTE_ETH_NAME_MAX_LEN);
> 	else
> -		snprintf(name, RTE_ETH_NAME_MAX_LEN - 1, "%s%d",
> -			 DEFAULT_TAP_NAME, (tap_unit - 1));
> +		snprintf(name, RTE_ETH_NAME_MAX_LEN, "%s%d",
> +			 DEFAULT_TAP_NAME, tun_unit - 1);

Was this meant to change from tap_unit to tun_unit here, if so why?
> 
> 	return 0;
> }
> -- 
> 2.20.1
> 

Regards,
Keith
  
Stephen Hemminger Jan. 11, 2019, 7:48 p.m. UTC | #2
On Fri, 11 Jan 2019 19:32:39 +0000
"Wiles, Keith" <keith.wiles@intel.com> wrote:

> > On Jan 11, 2019, at 12:06 PM, Stephen Hemminger <stephen@networkplumber.org> wrote:
> > 
> > The code for set_interface_name was incorrectly assuming that
> > space for null byte was necessary with snprintf/strlcpy.
> > 
> > Fixes: 02f96a0a82d1 ("net/tap: add TUN/TAP device PMD")
> > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> > ---
> > drivers/net/tap/rte_eth_tap.c | 6 +++---
> > 1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
> > index 1c00681ba0eb..d7f77d664502 100644
> > --- a/drivers/net/tap/rte_eth_tap.c
> > +++ b/drivers/net/tap/rte_eth_tap.c
> > @@ -1892,10 +1892,10 @@ set_interface_name(const char *key __rte_unused,
> > 	char *name = (char *)extra_args;
> > 
> > 	if (value)
> > -		strlcpy(name, value, RTE_ETH_NAME_MAX_LEN - 1);
> > +		strlcpy(name, value, RTE_ETH_NAME_MAX_LEN);
> > 	else
> > -		snprintf(name, RTE_ETH_NAME_MAX_LEN - 1, "%s%d",
> > -			 DEFAULT_TAP_NAME, (tap_unit - 1));
> > +		snprintf(name, RTE_ETH_NAME_MAX_LEN, "%s%d",
> > +			 DEFAULT_TAP_NAME, tun_unit - 1);  
> 
> Was this meant to change from tap_unit to tun_unit here, if so why?

Accident. tun_unit disappears in later patch.
  
Wiles, Keith Jan. 11, 2019, 7:49 p.m. UTC | #3
> On Jan 11, 2019, at 1:48 PM, Stephen Hemminger <stephen@networkplumber.org> wrote:
> 
> On Fri, 11 Jan 2019 19:32:39 +0000
> "Wiles, Keith" <keith.wiles@intel.com> wrote:
> 
>>> On Jan 11, 2019, at 12:06 PM, Stephen Hemminger <stephen@networkplumber.org> wrote:
>>> 
>>> The code for set_interface_name was incorrectly assuming that
>>> space for null byte was necessary with snprintf/strlcpy.
>>> 
>>> Fixes: 02f96a0a82d1 ("net/tap: add TUN/TAP device PMD")
>>> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
>>> ---
>>> drivers/net/tap/rte_eth_tap.c | 6 +++---
>>> 1 file changed, 3 insertions(+), 3 deletions(-)
>>> 
>>> diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
>>> index 1c00681ba0eb..d7f77d664502 100644
>>> --- a/drivers/net/tap/rte_eth_tap.c
>>> +++ b/drivers/net/tap/rte_eth_tap.c
>>> @@ -1892,10 +1892,10 @@ set_interface_name(const char *key __rte_unused,
>>> 	char *name = (char *)extra_args;
>>> 
>>> 	if (value)
>>> -		strlcpy(name, value, RTE_ETH_NAME_MAX_LEN - 1);
>>> +		strlcpy(name, value, RTE_ETH_NAME_MAX_LEN);
>>> 	else
>>> -		snprintf(name, RTE_ETH_NAME_MAX_LEN - 1, "%s%d",
>>> -			 DEFAULT_TAP_NAME, (tap_unit - 1));
>>> +		snprintf(name, RTE_ETH_NAME_MAX_LEN, "%s%d",
>>> +			 DEFAULT_TAP_NAME, tun_unit - 1);  
>> 
>> Was this meant to change from tap_unit to tun_unit here, if so why?
> 
> Accident. tun_unit disappears in later patch.

OK, great

Regards,
Keith
  

Patch

diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index 1c00681ba0eb..d7f77d664502 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -1892,10 +1892,10 @@  set_interface_name(const char *key __rte_unused,
 	char *name = (char *)extra_args;
 
 	if (value)
-		strlcpy(name, value, RTE_ETH_NAME_MAX_LEN - 1);
+		strlcpy(name, value, RTE_ETH_NAME_MAX_LEN);
 	else
-		snprintf(name, RTE_ETH_NAME_MAX_LEN - 1, "%s%d",
-			 DEFAULT_TAP_NAME, (tap_unit - 1));
+		snprintf(name, RTE_ETH_NAME_MAX_LEN, "%s%d",
+			 DEFAULT_TAP_NAME, tun_unit - 1);
 
 	return 0;
 }