Message ID | 1404307229-19186-4-git-send-email-andriy.shevchenko@linux.intel.com (mailing list archive) |
---|---|
State | Not Applicable, archived |
Headers | show |
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. -- To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, 2014-07-02 at 06:43 -0700, Joe Perches wrote: > 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. [] > 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. Might be, but it - doesn't reduce necessity of string_escape_mem (not only ssid are escaped in kernel) - prevents user to choose a rule what exactly their would like to escape (look at the other patches against ssid escaping)
On Wed, 2014-07-02 at 17:06 +0300, Andy Shevchenko wrote: > On Wed, 2014-07-02 at 06:43 -0700, Joe Perches wrote: > > 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. > > [] > > > 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. > > Might be, but it > - doesn't reduce necessity of string_escape_mem (not only ssid are > escaped in kernel) > - prevents user to choose a rule what exactly their would like to > escape (look at the other patches against ssid escaping) > %pE<FLAGS> would allow the same arbitrary combinations of your flags. -- To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, 2014-07-02 at 09:30 -0700, Joe Perches wrote: > On Wed, 2014-07-02 at 17:06 +0300, Andy Shevchenko wrote: > > On Wed, 2014-07-02 at 06:43 -0700, Joe Perches wrote: > > > 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. > > > > [] > > > > > 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. > > > > Might be, but it > > - doesn't reduce necessity of string_escape_mem (not only ssid are > > escaped in kernel) > > - prevents user to choose a rule what exactly their would like to > > escape (look at the other patches against ssid escaping) > > > > %pE<FLAGS> would allow the same arbitrary combinations > of your flags. Makes sense. Can do this as a separate patch. Though I would have a sane default for escaping SSIDs. I hope that one from print_ssid() could be the one.
diff --git a/net/wireless/lib80211.c b/net/wireless/lib80211.c index a55c27b..0c2f67b 100644 --- a/net/wireless/lib80211.c +++ b/net/wireless/lib80211.c @@ -22,6 +22,7 @@ #include <linux/init.h> #include <linux/slab.h> #include <linux/string.h> +#include <linux/string_helpers.h> #include <net/lib80211.h> @@ -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; }
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. Additionally the \f, \v, \a, and \e are escaped to their alphabetic representation. It's safe to do since the print_ssid() is currently used for messaging only. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> --- net/wireless/lib80211.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-)