mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-06 10:50:14 +01:00
supplicant: Add a new validation type for UTF-8 strings
This commit is contained in:
parent
6346bd60be
commit
ef9551bcf3
3 changed files with 27 additions and 0 deletions
|
|
@ -293,6 +293,7 @@ get_hash_cb (gpointer key, gpointer value, gpointer user_data)
|
|||
g_value_set_int (variant, atoi (opt->value));
|
||||
break;
|
||||
case TYPE_BYTES:
|
||||
case TYPE_UTF8:
|
||||
array = g_byte_array_sized_new (opt->len);
|
||||
g_byte_array_append (array, (const guint8 *) opt->value, opt->len);
|
||||
g_value_init (variant, DBUS_TYPE_G_UCHAR_ARRAY);
|
||||
|
|
|
|||
|
|
@ -44,6 +44,10 @@ static gboolean validate_type_bytes (const struct Opt * opt,
|
|||
const char * value,
|
||||
const guint32 len);
|
||||
|
||||
static gboolean validate_type_utf8 (const struct Opt *opt,
|
||||
const char * value,
|
||||
const guint32 len);
|
||||
|
||||
static gboolean validate_type_keyword (const struct Opt * opt,
|
||||
const char * value,
|
||||
const guint32 len);
|
||||
|
|
@ -58,6 +62,7 @@ struct validate_entry {
|
|||
static const struct validate_entry validate_table[] = {
|
||||
{ TYPE_INT, validate_type_int },
|
||||
{ TYPE_BYTES, validate_type_bytes },
|
||||
{ TYPE_UTF8, validate_type_utf8 },
|
||||
{ TYPE_KEYWORD, validate_type_keyword },
|
||||
};
|
||||
|
||||
|
|
@ -173,6 +178,26 @@ validate_type_bytes (const struct Opt * opt,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
validate_type_utf8 (const struct Opt *opt,
|
||||
const char * value,
|
||||
const guint32 len)
|
||||
{
|
||||
guint32 check_len;
|
||||
|
||||
g_return_val_if_fail (opt != NULL, FALSE);
|
||||
g_return_val_if_fail (value != NULL, FALSE);
|
||||
|
||||
check_len = opt->int_high ? opt->int_high : 255;
|
||||
/* Note that we deliberately don't validate the UTF-8, because
|
||||
some "UTF-8" fields, such as 8021x.password, do not actually
|
||||
have to be valid UTF-8 */
|
||||
if (g_utf8_strlen (value, len) > check_len)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
validate_type_keyword (const struct Opt * opt,
|
||||
const char * value,
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ typedef enum OptType {
|
|||
TYPE_INVALID = 0,
|
||||
TYPE_INT,
|
||||
TYPE_BYTES,
|
||||
TYPE_UTF8,
|
||||
TYPE_KEYWORD,
|
||||
TYPE_STRING
|
||||
} OptType;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue