diff options
| author | Michael Biebl <biebl@debian.org> | 2017-07-12 17:57:30 +0200 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2017-07-12 17:57:30 +0200 |
| commit | b9f0451fa35393ceedf6d9d20b78c43578ebea5d (patch) | |
| tree | 417afcdd717020ad44e25fadee4b89de23316e83 /clients/cli/settings.c | |
| parent | c333f062ddcba9b35330647bf6cbd0a07f2d786e (diff) | |
New upstream version 1.8.2 upstream/1.8.2
Diffstat (limited to 'clients/cli/settings.c')
| -rw-r--r-- | clients/cli/settings.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/clients/cli/settings.c b/clients/cli/settings.c index 87b1f50f..e0f045ac 100644 --- a/clients/cli/settings.c +++ b/clients/cli/settings.c @@ -1643,11 +1643,12 @@ nmc_util_is_domain (const char *domain) } static gboolean -nmc_property_set_byte_array (NMSetting *setting, const char *prop, const char *val, GError **error) +nmc_property_set_bytes (NMSetting *setting, const char *prop, const char *val, GError **error) { - char **strv = NULL, **iter; - char *val_strip; + gs_free char *val_strip = NULL; + gs_strfreev char **strv = NULL; const char *delimiters = " \t,"; + char **iter; long int val_int; GBytes *bytes; GByteArray *array = NULL; @@ -1659,30 +1660,33 @@ nmc_property_set_byte_array (NMSetting *setting, const char *prop, const char *v /* First try hex string in the format of AAbbCCDd */ bytes = nm_utils_hexstr2bin (val_strip); - if (bytes) { - array = g_bytes_unref_to_array (bytes); + if (bytes) goto done; - } /* Otherwise, consider the following format: AA b 0xCc D */ strv = nmc_strsplit_set (val_strip, delimiters, 0); array = g_byte_array_sized_new (g_strv_length (strv)); for (iter = strv; iter && *iter; iter++) { + guint8 v8; + if (!nmc_string_to_int_base (g_strstrip (*iter), 16, TRUE, 0, 255, &val_int)) { g_set_error (error, 1, 0, _("'%s' is not a valid hex character"), *iter); + g_byte_array_free (array, TRUE); success = FALSE; goto done; } - g_byte_array_append (array, (const guint8 *) &val_int, 1); + v8 = val_int; + g_byte_array_append (array, &v8, 1); } + bytes = g_byte_array_free_to_bytes (array); done: if (success) - g_object_set (setting, prop, array, NULL); + g_object_set (setting, prop, bytes, NULL); + + if (bytes) + g_bytes_unref (bytes); - g_strfreev (strv); - if (array) - g_byte_array_free (array, TRUE); return success; } @@ -2186,7 +2190,7 @@ DEFINE_ALLOWED_VAL_FUNC (nmc_property_802_1X_allowed_phase2_autheap, _802_1X_val static gboolean nmc_property_802_1X_set_password_raw (NMSetting *setting, const char *prop, const char *val, GError **error) { - return nmc_property_set_byte_array (setting, prop, val, error); + return nmc_property_set_bytes (setting, prop, val, error); } static const char * |