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
"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;
}
"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;
}