Commit 2819f8ad authored by John W. Linville's avatar John W. Linville

wireless: escape_ssid should handle non-printables

Also use common backslash sequences like \t, \n, \r, and \\ as well as \0.
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent c5d3dce8
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
#include <linux/module.h> #include <linux/module.h>
#include <linux/ctype.h>
#include <linux/ieee80211.h> #include <linux/ieee80211.h>
#include <net/lib80211.h> #include <net/lib80211.h>
...@@ -20,19 +21,31 @@ MODULE_LICENSE("GPL"); ...@@ -20,19 +21,31 @@ MODULE_LICENSE("GPL");
const char *escape_ssid(const char *ssid, u8 ssid_len) 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; const char *s = ssid;
char *d = escaped; char *d = escaped;
ssid_len = min_t(u8, ssid_len, IEEE80211_MAX_SSID_LEN); ssid_len = min_t(u8, ssid_len, IEEE80211_MAX_SSID_LEN);
while (ssid_len--) { while (ssid_len--) {
if (*s == '\0') { if (isprint(*s)) {
*d++ = *s++;
continue;
}
*d++ = '\\'; *d++ = '\\';
if (*s == '\0')
*d++ = '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++; s++;
} else {
*d++ = *s++;
}
} }
*d = '\0'; *d = '\0';
return escaped; return escaped;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment