diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 6384e2e9a1..ab5de92a46 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -3995,16 +3995,13 @@ GByteArray * nm_utils_hwaddr_atoba(const char *asc, gsize length) { GByteArray *ba; - gsize l; g_return_val_if_fail(asc, NULL); g_return_val_if_fail(length > 0 && length <= NM_UTILS_HWADDR_LEN_MAX, NULL); ba = g_byte_array_sized_new(length); g_byte_array_set_size(ba, length); - if (!_nm_utils_hwaddr_aton(asc, ba->data, length, &l)) - goto fail; - if (length != l) + if (!_nm_utils_hwaddr_aton_exact(asc, ba->data, length)) goto fail; return ba; @@ -4029,17 +4026,11 @@ fail: guint8 * nm_utils_hwaddr_aton(const char *asc, gpointer buffer, gsize length) { - gsize l; - g_return_val_if_fail(asc, NULL); g_return_val_if_fail(buffer, NULL); g_return_val_if_fail(length > 0 && length <= NM_UTILS_HWADDR_LEN_MAX, NULL); - if (!_nm_utils_hwaddr_aton(asc, buffer, length, &l)) - return NULL; - if (length != l) - return NULL; - return buffer; + return _nm_utils_hwaddr_aton_exact(asc, buffer, length); } /** diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h index fe61459f5f..abcb20abaf 100644 --- a/shared/nm-glib-aux/nm-shared-utils.h +++ b/shared/nm-glib-aux/nm-shared-utils.h @@ -2092,6 +2092,24 @@ _nm_utils_hwaddr_aton(const char *asc, gpointer buffer, gsize buffer_length, gsi out_length); } +static inline guint8 * +_nm_utils_hwaddr_aton_exact(const char *asc, gpointer buffer, gsize buffer_length) +{ + g_return_val_if_fail(asc, NULL); + g_return_val_if_fail(buffer, NULL); + g_return_val_if_fail(buffer_length > 0, NULL); + + return nm_utils_hexstr2bin_full(asc, + FALSE, + TRUE, + FALSE, + ":-", + buffer_length, + buffer, + buffer_length, + NULL); +} + static inline const char * _nm_utils_hwaddr_ntoa(gconstpointer addr, gsize addr_len, diff --git a/src/platform/nm-platform-utils.c b/src/platform/nm-platform-utils.c index f0dfc074a7..75ac769a74 100644 --- a/src/platform/nm-platform-utils.c +++ b/src/platform/nm-platform-utils.c @@ -1439,7 +1439,7 @@ nmp_utils_ethtool_set_wake_on_lan(int ifindex, wol_info.wolopts |= WAKE_MAGIC; if (wol_password) { - if (!nm_utils_hwaddr_aton(wol_password, wol_info.sopass, ETH_ALEN)) { + if (!_nm_utils_hwaddr_aton_exact(wol_password, wol_info.sopass, ETH_ALEN)) { nm_log_dbg(LOGD_PLATFORM, "ethtool[%d]: couldn't parse Wake-on-LAN password '%s'", ifindex,