diff options
author | John W. Linville <linville@tuxdriver.com> | 2008-09-30 17:50:31 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2008-10-31 19:00:49 -0400 |
commit | 2819f8ad6da1e24b5dd94a221978e61f2a9c972a (patch) | |
tree | d2bd598b6a6e9029fb7399571826e6b2cdef2d0a /net | |
parent | c5d3dce875ef055ed9b14f169cc967cc2c8faf1f (diff) |
wireless: escape_ssid should handle non-printables
Also use common backslash sequences like \t, \n, \r, and \\ as well as \0.
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'net')
-rw-r--r-- | net/wireless/lib80211.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/net/wireless/lib80211.c b/net/wireless/lib80211.c index 872cc8dc00a3..b8e34d31e757 100644 --- a/net/wireless/lib80211.c +++ b/net/wireless/lib80211.c | |||
@@ -6,6 +6,7 @@ | |||
6 | */ | 6 | */ |
7 | 7 | ||
8 | #include <linux/module.h> | 8 | #include <linux/module.h> |
9 | #include <linux/ctype.h> | ||
9 | #include <linux/ieee80211.h> | 10 | #include <linux/ieee80211.h> |
10 | 11 | ||
11 | #include <net/lib80211.h> | 12 | #include <net/lib80211.h> |
@@ -20,19 +21,31 @@ MODULE_LICENSE("GPL"); | |||
20 | 21 | ||
21 | const char *escape_ssid(const char *ssid, u8 ssid_len) | 22 | const char *escape_ssid(const char *ssid, u8 ssid_len) |
22 | { | 23 | { |
23 | static char escaped[IEEE80211_MAX_SSID_LEN * 2 + 1]; | 24 | static char escaped[IEEE80211_MAX_SSID_LEN * 4 + 1]; |
24 | const char *s = ssid; | 25 | const char *s = ssid; |
25 | char *d = escaped; | 26 | char *d = escaped; |
26 | 27 | ||
27 | ssid_len = min_t(u8, ssid_len, IEEE80211_MAX_SSID_LEN); | 28 | ssid_len = min_t(u8, ssid_len, IEEE80211_MAX_SSID_LEN); |
28 | while (ssid_len--) { | 29 | while (ssid_len--) { |
29 | if (*s == '\0') { | 30 | if (isprint(*s)) { |
30 | *d++ = '\\'; | ||
31 | *d++ = '0'; | ||
32 | s++; | ||
33 | } else { | ||
34 | *d++ = *s++; | 31 | *d++ = *s++; |
32 | continue; | ||
35 | } | 33 | } |
34 | |||
35 | *d++ = '\\'; | ||
36 | if (*s == '\0') | ||
37 | *d++ = '0'; | ||
38 | else if (*s == '\n') | ||
39 | *d++ = 'n'; | ||
40 | else if (*s == '\r') | ||
41 | *d++ = 'r'; | ||
42 | else if (*s == '\t') | ||
43 | *d++ = 't'; | ||
44 | else if (*s == '\\') | ||
45 | *d++ = '\\'; | ||
46 | else | ||
47 | d += snprintf(d, 3, "%03o", *s); | ||
48 | s++; | ||
36 | } | 49 | } |
37 | *d = '\0'; | 50 | *d = '\0'; |
38 | return escaped; | 51 | return escaped; |