[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH] tools/xenstat: handle network interface name in uppercase.



I wasn't CC'ed so this fled my attention.

On Fri, Mar 11, 2016 at 03:18:01PM -0500, Zhigang Wang wrote:
> xentop will segmentation fault in this case:
> 
>   # ip link set eth1 down
>   # ip link set eth1 name ETH
>   # xentop
> 
> This patch will let xentop to handle all uppercase network interface name.
> 
> Signed-off-by: Zhigang Wang <zhigang.x.wang@xxxxxxxxxx>
> ---
>  tools/xenstat/libxenstat/src/xenstat_linux.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/xenstat/libxenstat/src/xenstat_linux.c 
> b/tools/xenstat/libxenstat/src/xenstat_linux.c
> index 931b24e..d33eca1 100644
> --- a/tools/xenstat/libxenstat/src/xenstat_linux.c
> +++ b/tools/xenstat/libxenstat/src/xenstat_linux.c
> @@ -101,6 +101,7 @@ int parseNetDevLine(char *line, char *iface, unsigned 
> long long *rxBytes, unsign
>       /* Temporary/helper variables */
>       int ret;
>       char *tmp;
> +     char *tmp2;
>       int i = 0, x = 0, col = 0;
>       regex_t r;
>       regmatch_t matches[19];
> @@ -221,8 +222,11 @@ int parseNetDevLine(char *line, char *iface, unsigned 
> long long *rxBytes, unsign
>                               }
>                               else
>                               /* There were errors when parsing this directly 
> in RE. strpbrk() helps */

This line indicates the most proper fix is to fix the regexp used to
also parse netdev name IMHO. That being said, there is no reason to
block a valid fix.

> -                             if (iface != NULL)
> -                                     strcpy(iface, strpbrk(tmp, 
> "abcdefghijklmnopqrstvuwxyz0123456789"));
> +                             if (iface != NULL) {
> +                                     tmp2 = strpbrk(tmp, 
> "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
> +                                     if (tmp2 != NULL)
> +                                             strcpy(iface, tmp2);
> +                             }

Please limit the scope of tmp2, if you only need that here, declare it
within this narrow scope please.


Wei.

>  
>                               memset(tmp, 0, matches[i].rm_eo - 
> matches[i].rm_so);
>                       }
> -- 
> 2.5.0
> 
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@xxxxxxxxxxxxx
> http://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.