wireless: escape_ssid should handle non-printables
authorJohn W. Linville <linville@tuxdriver.com>
Tue, 30 Sep 2008 21:50:31 +0000 (17:50 -0400)
committerJohn W. Linville <linville@tuxdriver.com>
Fri, 31 Oct 2008 23:00:49 +0000 (19:00 -0400)
Also use common backslash sequences like \t, \n, \r, and \\ as well as \0.

Signed-off-by: John W. Linville <linville@tuxdriver.com>
net/wireless/lib80211.c

index 872cc8dc00a37475a8a245c890c7ef18954bd972..b8e34d31e757abd623f932a97a5d3702acafa44c 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 #include <linux/module.h>
+#include <linux/ctype.h>
 #include <linux/ieee80211.h>
 
 #include <net/lib80211.h>
@@ -20,19 +21,31 @@ MODULE_LICENSE("GPL");
 
 const char *escape_ssid(const char *ssid, u8 ssid_len)
 {
-       static char escaped[IEEE80211_MAX_SSID_LEN * 2 + 1];
+       static char escaped[IEEE80211_MAX_SSID_LEN * 4 + 1];
        const char *s = ssid;
        char *d = escaped;
 
        ssid_len = min_t(u8, ssid_len, IEEE80211_MAX_SSID_LEN);
        while (ssid_len--) {
-               if (*s == '\0') {
-                       *d++ = '\\';
-                       *d++ = '0';
-                       s++;
-               } else {
+               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 = '\0';
        return escaped;