diff options
author | David Shea <dshea@redhat.com> | 2015-07-14 15:25:52 -0400 |
---|---|---|
committer | Jiří Klimeš <jklimes@redhat.com> | 2015-07-16 14:22:03 +0200 |
commit | 568b4ad31f36690091a03cbff0fc7c3a9556e028 (patch) | |
tree | 7b5485bf90be82b97a235451c9f292fd754840f6 | |
parent | 7b6299d8dd969c10ee0b5ec203d812cf9a6c7a56 (diff) | |
download | NetworkManager-568b4ad31f36690091a03cbff0fc7c3a9556e028.tar.gz |
libnm: handle illegal characters in nm_utils_ssid_to_utf8() (rh #1243078)
g_convert_with_fallback() will fail if the SSID contains characters that
are not legal in the source encoding, which, if $LANG is not set, will
be ASCII. If this happens, replace all non-ASCII and non-printable
characters with '?'. It is possible that nm_utils_ssid_to_utf8() will
now return an empty string (e.g., the source string is actually
big-endian UTF-16 and g_strcanon() stops on the first byte), but it will
not return NULL.
https://bugzilla.redhat.com/show_bug.cgi?id=1243078
-rw-r--r-- | libnm-core/nm-utils.c | 15 | ||||
-rw-r--r-- | libnm-util/nm-utils.c | 15 |
2 files changed, 30 insertions, 0 deletions
diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 3e1cf807e1..89a960e07a 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -317,6 +317,21 @@ nm_utils_ssid_to_utf8 (const guint8 *ssid, gsize len) "UTF-8", e1, "?", NULL, NULL, NULL); } + if (!converted) { + /* If there is still no converted string, the SSID probably + * contains characters not valid in the current locale. Convert + * the string to ASCII instead. + */ + + /* Use the printable range of 0x20-0x7E */ + gchar *valid_chars = " !\"#$%&'()*+,-./0123456789:;<=>?@" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`" + "abcdefghijklmnopqrstuvwxyz{|}~"; + + converted = g_strndup ((const gchar *)ssid, len); + g_strcanon (converted, valid_chars, '?'); + } + return converted; } diff --git a/libnm-util/nm-utils.c b/libnm-util/nm-utils.c index d0c2ca31f8..143063e7f5 100644 --- a/libnm-util/nm-utils.c +++ b/libnm-util/nm-utils.c @@ -332,6 +332,21 @@ nm_utils_ssid_to_utf8 (const GByteArray *ssid) "UTF-8", e1, "?", NULL, NULL, NULL); } + if (!converted) { + /* If there is still no converted string, the SSID probably + * contains characters not valid in the current locale. Convert + * the string to ASCII instead. + */ + + /* Use the printable range of 0x20-0x7E */ + gchar *valid_chars = " !\"#$%&'()*+,-./0123456789:;<=>?@" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`" + "abcdefghijklmnopqrstuvwxyz{|}~"; + + converted = g_strndup ((const gchar *)ssid->data, ssid->len); + g_strcanon (converted, valid_chars, '?'); + } + return converted; } |