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.
This commit is contained in:
@@ -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);
|
||||
|
@@ -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)) {
|
||||
|
Reference in New Issue
Block a user