Re: [PATCH] usb: gadget: ether: Fix MAC address parsing

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

 



Hi Krzysztof,

On 2015-04-27 11:42, Krzysztof Opasiak wrote:
> MAC address is often written without leading zeros.
> 
> Example:
> 00:14:3d:0f:ff:fe can be written as 0:14:3d:f:ff:fe
> 
> Convention of skipping leading zeros is used in libc.
> enther_ntoa_r() generates MAC address without leading
> zeros.
> 
> Fix get_ether_addr() to correctly parse MAC address
> with and without leading zeros.

Thought about creating such a patch too, thanks for looking into it.

> 
> Signed-off-by: Krzysztof Opasiak <k.opasiak@xxxxxxxxxxx>
> ---
>  drivers/usb/gadget/function/u_ether.c |    8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/gadget/function/u_ether.c
> b/drivers/usb/gadget/function/u_ether.c
> index f1fd777..1e3ee2a 100644
> --- a/drivers/usb/gadget/function/u_ether.c
> +++ b/drivers/usb/gadget/function/u_ether.c
> @@ -713,9 +713,11 @@ static int get_ether_addr(const char *str, u8 *dev_addr)
>  
>  			if ((*str == '.') || (*str == ':'))
>  				str++;
> -			num = hex_to_bin(*str++) << 4;
> -			num |= hex_to_bin(*str++);
> -			dev_addr [i] = num;
> +
> +			num = hex_to_bin(*str++);
> +			if ((*str != '.') && (*str != ':'))
> +				num = num << 4 | hex_to_bin(*str++);
> +			dev_addr[i] = num;

This should definitely work, but seems a bit complex to solve the
problem.

When looking a bit close, this function seems to parse beyond the input
strings end, which clearly is not a nice thing or even a security issue.
Will try to improve it.

--
Stefan

>  		}
>  		if (is_valid_ether_addr(dev_addr))
>  			return 0;

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux