lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 28 May 2012 13:01:05 +0300
From:	Andy Shevchenko <andy.shevchenko@...il.com>
To:	Andrei Emeltchenko <Andrei.Emeltchenko.news@...il.com>
Cc:	linux-bluetooth@...r.kernel.org, akpm@...ux-foundation.org,
	linux-kernel@...r.kernel.org, adobriyan@...il.com,
	andriy.shevchenko@...ux.intel.com
Subject: Re: [PATCHv2] vsprintf: Add %pMR for Bluetooth MAC address

On Mon, May 28, 2012 at 12:00 PM, Andrei Emeltchenko
<Andrei.Emeltchenko.news@...il.com> wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@...el.com>
>
> Bluetooth uses mostly LE byte order which is reversed for visual
> interpretation. Currently in Bluetooth in use unsafe batostr function.
>
> This is slightly modified version of Joe Perches <joe@...ches.com>
> patch (sent Sat, Dec 4, 2010).
>
> Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@...el.com>
> ---
>        v2: changed bluetooth to reversed, syntax fixes
>
>  lib/vsprintf.c |   22 +++++++++++++++++-----
>  1 file changed, 17 insertions(+), 5 deletions(-)
>
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index abbabec..d98b12d 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -557,17 +557,27 @@ char *mac_address_string(char *buf, char *end, u8 *addr,
>  {
>        char mac_addr[sizeof("xx:xx:xx:xx:xx:xx")];
>        char *p = mac_addr;
> -       int i;
> +       int i, index;
>        char separator;
> +       bool reversed = false;
>
> -       if (fmt[1] == 'F') {            /* FDDI canonical format */
> +       switch (fmt[1]) {
> +       case 'F':
>                separator = '-';
> -       } else {
> +               break;
> +
> +       case 'R':
> +               reversed = true;
> +               /* fall through */
This solution looks a bit limited. On one hand it makes difficult to add another
case where format specifies colon separator with something else. On
the other hand
I don't see any troubles if you allow reverse as a modifier for both
cases %pMF & %pM

> +
> +       default:
>                separator = ':';
> +               break;
>        }
>
>        for (i = 0; i < 6; i++) {
> -               p = hex_byte_pack(p, addr[i]);
> +               index = !reversed ? i : 5 - i;
> +               p = hex_byte_pack(p, addr[index]);
I guess instead of using additional variable (index), you could use
just normal if () {} else {} sentence
here.

>                if (fmt[0] == 'M' && i != 5)
>                        *p++ = separator;
>        }
> @@ -830,6 +840,7 @@ int kptr_restrict __read_mostly;
>  * - 'm' For a 6-byte MAC address, it prints the hex address without colons
>  * - 'MF' For a 6-byte MAC FDDI address, it prints the address
>  *       with a dash-separated hex notation
> + * - '[mM]R For a 6-byte MAC address, Reverse order (Bluetooth)
>  * - 'I' [46] for IPv4/IPv6 addresses printed in the usual way
>  *       IPv4 uses dot-separated decimal without leading 0's (1.2.3.4)
>  *       IPv6 uses colon separated network-order 16 bit hex with leading 0's
> @@ -890,7 +901,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
>                return resource_string(buf, end, ptr, spec, fmt);
>        case 'M':                       /* Colon separated: 00:01:02:03:04:05 */
>        case 'm':                       /* Contiguous: 000102030405 */
> -                                       /* [mM]F (FDDI, bit reversed) */
> +                                       /* [mM]F (FDDI) */
> +                                       /* [mM]R (Reverse order; Bluetooth) */
>                return mac_address_string(buf, end, ptr, spec, fmt);
>        case 'I':                       /* Formatted IP supported
>                                         * 4:   1.2.3.4



-- 
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ