diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2014-08-25 12:46:27 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2014-08-25 12:46:27 +0000 |
commit | 0347465420399eb8bf72c454ebc1d58d9bda2858 (patch) | |
tree | d98c57b9fa46e4091701e647ae3a80bd4af56165 /package/network | |
parent | 8ea8d57b124f165f3b0a2473c8a940d3097140d6 (diff) | |
download | upstream-0347465420399eb8bf72c454ebc1d58d9bda2858.tar.gz upstream-0347465420399eb8bf72c454ebc1d58d9bda2858.tar.bz2 upstream-0347465420399eb8bf72c454ebc1d58d9bda2858.zip |
BB: iwinfo: properly decode SSIDs when scanning through wpa_supplicant
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Backport of r42273
git-svn-id: svn://svn.openwrt.org/openwrt/branches/barrier_breaker@42285 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'package/network')
-rw-r--r-- | package/network/utils/iwinfo/Makefile | 2 | ||||
-rw-r--r-- | package/network/utils/iwinfo/src/iwinfo_nl80211.c | 65 |
2 files changed, 63 insertions, 4 deletions
diff --git a/package/network/utils/iwinfo/Makefile b/package/network/utils/iwinfo/Makefile index e4ee73a112..db46bbc07d 100644 --- a/package/network/utils/iwinfo/Makefile +++ b/package/network/utils/iwinfo/Makefile @@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=libiwinfo -PKG_RELEASE:=50 +PKG_RELEASE:=51 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) PKG_CONFIG_DEPENDS := \ diff --git a/package/network/utils/iwinfo/src/iwinfo_nl80211.c b/package/network/utils/iwinfo/src/iwinfo_nl80211.c index 33c62387e3..7711b61102 100644 --- a/package/network/utils/iwinfo/src/iwinfo_nl80211.c +++ b/package/network/utils/iwinfo/src/iwinfo_nl80211.c @@ -1881,11 +1881,70 @@ static int nl80211_get_scanlist_nl(const char *ifname, char *buf, int *len) return *len ? 0 : -1; } +static int wpasupp_ssid_decode(const char *in, char *out, int outlen) +{ +#define hex(x) \ + (((x) >= 'a') ? ((x) - 'a' + 10) : \ + (((x) >= 'A') ? ((x) - 'A' + 10) : ((x) - '0'))) + + int len = 0; + + while (*in) + { + if (len + 1 >= outlen) + break; + + switch (*in) + { + case '\\': + in++; + switch (*in) + { + case 'n': + out[len++] = '\n'; in++; + break; + + case 'r': + out[len++] = '\r'; in++; + break; + + case 't': + out[len++] = '\t'; in++; + break; + + case 'e': + out[len++] = '\e'; in++; + break; + + case 'x': + if (isxdigit(*(in+1)) && isxdigit(*(in+2))) + out[len++] = hex(*(in+1)) * 16 + hex(*(in+2)); + in += 3; + break; + + default: + out[len++] = *in++; + break; + } + break; + + default: + out[len++] = *in++; + break; + } + } + + if (outlen > len) + out[len] = '\0'; + + return len; +} + static int nl80211_get_scanlist(const char *ifname, char *buf, int *len) { int freq, rssi, qmax, count, mode; char *res; - char ssid[128] = { 0 }; + char ssid[129] = { 0 }; char bssid[18] = { 0 }; char cipher[256] = { 0 }; @@ -1930,7 +1989,7 @@ static int nl80211_get_scanlist(const char *ifname, char *buf, int *len) count++; goto nextline; } - if (sscanf(res, "%17s %d %d %255s%*[ \t]%127[^\n]\n", + if (sscanf(res, "%17s %d %d %255s%*[ \t]%128[^\n]\n", bssid, &freq, &rssi, cipher, ssid) < 5) { /* skip malformed lines */ @@ -1945,7 +2004,7 @@ static int nl80211_get_scanlist(const char *ifname, char *buf, int *len) e->mac[5] = strtol(&bssid[15], NULL, 16); /* SSID */ - memcpy(e->ssid, ssid, min(strlen(ssid), sizeof(e->ssid) - 1)); + wpasupp_ssid_decode(ssid, e->ssid, sizeof(e->ssid)); /* Mode (assume master) */ if (strstr(cipher,"[MESH]")) |