diff options
author | Thomas Haller <thaller@redhat.com> | 2018-09-03 11:22:34 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2018-09-03 18:13:36 +0200 |
commit | de12982661a647d4558e24bfc3e033719a25d3a4 (patch) | |
tree | d9c2095bd979d31379396817c93216f29af6fcb5 | |
parent | 362b7d216d7c80b1052cc47ce307bc670dd30611 (diff) | |
download | NetworkManager-de12982661a647d4558e24bfc3e033719a25d3a4.tar.gz |
libnm-core: expose _nm_utils_str2bin_full() as internal API
We only exposed wrappers around this function, but all of them have
different behavior, and none exposes all possible features. For example,
nm_utils_hexstr2bin() strips leading "0x", but it does not clear
the data on failure (nm_explicit_bzero()). Instead of adding more
wrappers, expose the underlying implementation, so that callers may
use the function the way they want it.
-rw-r--r-- | libnm-core/nm-core-internal.h | 7 | ||||
-rw-r--r-- | libnm-core/nm-utils.c | 20 |
2 files changed, 17 insertions, 10 deletions
diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index 614e017490..f19709dfc6 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -215,6 +215,13 @@ const char *nm_utils_hwaddr_ntoa_buf (gconstpointer addr, gsize addr_len, gboole char *_nm_utils_bin2str (gconstpointer addr, gsize length, gboolean upper_case); void _nm_utils_bin2str_full (gconstpointer addr, gsize length, const char delimiter, gboolean upper_case, char *out); +guint8 *_nm_utils_str2bin_full (const char *asc, + gboolean delimiter_required, + const char *delimiter_candidates, + guint8 *buffer, + gsize buffer_length, + gsize *out_len); + GSList * _nm_utils_hash_values_to_slist (GHashTable *hash); GHashTable *_nm_utils_copy_strdict (GHashTable *strdict); diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 1ca78421c3..c9162e971e 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -3526,13 +3526,13 @@ nm_utils_hwaddr_len (int type) g_return_val_if_reached (0); } -static guint8 * -_str2bin (const char *asc, - gboolean delimiter_required, - const char *delimiter_candidates, - guint8 *buffer, - gsize buffer_length, - gsize *out_len) +guint8 * +_nm_utils_str2bin_full (const char *asc, + gboolean delimiter_required, + const char *delimiter_candidates, + guint8 *buffer, + gsize buffer_length, + gsize *out_len) { const char *in = asc; guint8 *out = buffer; @@ -3602,7 +3602,7 @@ _str2bin (const char *asc, return buffer; } -#define hwaddr_aton(asc, buffer, buffer_length, out_len) _str2bin ((asc), TRUE, ":-", (buffer), (buffer_length), (out_len)) +#define hwaddr_aton(asc, buffer, buffer_length, out_len) _nm_utils_str2bin_full ((asc), TRUE, ":-", (buffer), (buffer_length), (out_len)) /** * nm_utils_hexstr2bin: @@ -3628,7 +3628,7 @@ nm_utils_hexstr2bin (const char *hex) buffer_length = strlen (hex) / 2 + 3; buffer = g_malloc (buffer_length); - if (!_str2bin (hex, FALSE, ":", buffer, buffer_length, &len)) { + if (!_nm_utils_str2bin_full (hex, FALSE, ":", buffer, buffer_length, &len)) { g_free (buffer); return NULL; } @@ -4508,7 +4508,7 @@ _nm_utils_dhcp_duid_valid (const char *duid, GBytes **out_duid_bin) return TRUE; } - if (_str2bin (duid, FALSE, ":", duid_arr, sizeof (duid_arr), &duid_len)) { + if (_nm_utils_str2bin_full (duid, FALSE, ":", duid_arr, sizeof (duid_arr), &duid_len)) { /* MAX DUID length is 128 octects + the type code (2 octects). */ if ( duid_len > 2 && duid_len <= (128 + 2)) { |