Search Linux Wireless

[PATCH 3/5] wireless: escape_ssid should handle non-printables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Also use common backslash sequences like \t, \n, \r, and \\ as well as \0.

Signed-off-by: John W. Linville <linville@xxxxxxxxxxxxx>
---
 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 872cc8d..b8e34d3 100644
--- a/net/wireless/lib80211.c
+++ b/net/wireless/lib80211.c
@@ -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;
-- 
1.5.4.3

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Host AP]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Linux Kernel]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]
  Powered by Linux