diff options
author | Thomas Haller <thaller@redhat.com> | 2017-11-24 12:27:53 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-11-24 12:28:56 +0100 |
commit | 26e7abc65e5e4a8739265308e2cc02409ac0f1af (patch) | |
tree | ea447afabadfa556acc7ae8009c009e1763869c0 | |
parent | bcf374e75f8c861b0658db72fdad57cd4845ca24 (diff) | |
download | NetworkManager-26e7abc65e5e4a8739265308e2cc02409ac0f1af.tar.gz |
libnm: be more accepting parsing boolean values in nm_utils_parse_variant_attributes()
We should use the same str2bool parser everywhere: _nm_utils_ascii_str_to_bool().
Incidentally, this function allows more forms of expressing a boolean
value.
$ nmcli connection modify "$CON" ipv4.routes '1.2.3.4/32 1.2.3.1 onlink=1'
Error: failed to modify ipv4.routes: invalid option 'onlink=1': invalid boolean value '1' for attribute 'onlink'.
-rw-r--r-- | libnm-core/nm-utils.c | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index ef72011393..69c8b66cd0 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -4969,13 +4969,10 @@ nm_utils_parse_variant_attributes (const char *string, } variant = g_variant_new_byte ((guchar) num); } else if (g_variant_type_equal ((*s)->type, G_VARIANT_TYPE_BOOLEAN)) { - gboolean b; + int b; - if (nm_streq (value, "true")) - b = TRUE; - else if (nm_streq (value, "false")) - b = FALSE; - else { + b = _nm_utils_ascii_str_to_bool (value, -1); + if (b == -1) { g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED, _("invalid boolean value '%s' for attribute '%s'"), value, name); return NULL; |