lkml.org 
[lkml]   [2014]   [Jul]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    SubjectRe: [PATCH 3/6] lib80211: re-use string_escape_mem_any_np()
    From
    Date
    On Wed, 2014-07-02 at 16:20 +0300, Andy Shevchenko wrote:
    > In kernel we have function to escape a given string. Let's use it instead of
    > custom approach.
    >
    > This fixes a bug. The current implementation wrongly prints octal numbers: only
    > two first digits are used in case when 3 are required and the rest of the
    > string ends up cut off.
    []
    > diff --git a/net/wireless/lib80211.c b/net/wireless/lib80211.c
    []
    > @@ -48,31 +49,10 @@ static void lib80211_crypt_deinit_handler(unsigned long data);
    >
    > const char *print_ssid(char *buf, const char *ssid, u8 ssid_len)
    > {
    > - const char *s = ssid;
    > char *d = buf;
    >
    > ssid_len = min_t(u8, ssid_len, IEEE80211_MAX_SSID_LEN);
    > - while (ssid_len--) {
    > - if (isprint(*s)) {
    > - *d++ = *s++;
    > - continue;
    > - }
    > -
    > - *d++ = '\\';
    > - if (*s == '\0')
    > - *d++ = '0';
    > - else if (*s == '\n')
    > - *d++ = 'n';
    > - else if (*s == '\r')
    > - *d++ = 'r';
    > - else if (*s == '\t')
    > - *d++ = 't';
    > - else if (*s == '\\')
    > - *d++ = '\\';
    > - else
    > - d += snprintf(d, 3, "%03o", *s);
    > - s++;
    > - }
    > + d += string_escape_mem_any_np(ssid, ssid_len, buf, ~0UL, NULL);
    > *d = '\0';
    > return buf;
    > }

    This code looks like it was adapted from the old print_mac
    ethernet code that was eventually replaced by a vsprintf
    pointer extension %pM

    So a better way to do this might be to add and use yet
    another vsprintf %p<foo> extension for ssids.




    \
     
     \ /
      Last update: 2014-07-02 16:21    [W:3.574 / U:0.804 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site