diff options
author | Thomas Haller <thaller@redhat.com> | 2021-01-05 13:58:09 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2021-01-08 16:32:48 +0100 |
commit | 2ba984a80a1a6b299692e6144c63f2068e3d21f4 (patch) | |
tree | 2f9764de5767e304f0d1667dd54ab475e0a96c98 | |
parent | 494819bbbf973bef683e17c0a4fe0c814b6ad838 (diff) | |
download | NetworkManager-2ba984a80a1a6b299692e6144c63f2068e3d21f4.tar.gz |
cloud-setup: strip whitespace from nmcs_utils_hwaddr_normalize()
This function should be accepting, and not reject leading/trailing
white space.
-rw-r--r-- | clients/cloud-setup/nm-cloud-setup-utils.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/clients/cloud-setup/nm-cloud-setup-utils.c b/clients/cloud-setup/nm-cloud-setup-utils.c index 38eb0bcf72..f09d1e5988 100644 --- a/clients/cloud-setup/nm-cloud-setup-utils.c +++ b/clients/cloud-setup/nm-cloud-setup-utils.c @@ -485,22 +485,30 @@ char * nmcs_utils_hwaddr_normalize(const char *hwaddr, gssize len) { gs_free char *hwaddr_clone = NULL; + char * hw; guint8 buf[ETH_ALEN]; + gsize l; nm_assert(len >= -1); if (len < 0) { if (!hwaddr) return NULL; - } else { - if (len == 0) - return NULL; - nm_assert(hwaddr); - hwaddr = nm_strndup_a(300, hwaddr, len, &hwaddr_clone); - } + l = strlen(hwaddr); + } else + l = len; + + if (l == 0) + return NULL; + + nm_assert(hwaddr); + hw = nm_strndup_a(300, hwaddr, l, &hwaddr_clone); + + g_strstrip(hw); + /* we cannot use _nm_utils_hwaddr_aton() because that requires a delimiter. * Azure exposes MAC addresses without delimiter, so accept that too. */ - if (!nm_utils_hexstr2bin_full(hwaddr, + if (!nm_utils_hexstr2bin_full(hw, FALSE, FALSE, FALSE, |