From 0e57603e4375ca77cb3c3987865e0293706172c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Fri, 30 Aug 2013 13:54:02 +0200 Subject: [PATCH] libnm-util: nm_utils_hwaddr_aton_len() allow hyphens in MAC string (rh #1002553) http://en.wikipedia.org/wiki/MAC_address#Notational_conventions Both 01:23:45:67:89:ab and 01-23-45-67-89-ab are used and valid. --- libnm-util/nm-utils.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libnm-util/nm-utils.c b/libnm-util/nm-utils.c index 29b08c02b9..e869e0ad94 100644 --- a/libnm-util/nm-utils.c +++ b/libnm-util/nm-utils.c @@ -1995,6 +1995,7 @@ nm_utils_hwaddr_ntoa (gconstpointer addr, int type) * @length: the expected length in bytes of the result * * Parses @asc and converts it to binary form in @buffer. + * Bytes in @asc can be sepatared by colons (:), or hyphens (-), but not mixed. * * Return value: @buffer, or %NULL if @asc couldn't be parsed * or would be shorter or longer than @length. @@ -2006,6 +2007,7 @@ nm_utils_hwaddr_aton_len (const char *asc, gpointer buffer, gsize length) { const char *in = asc; guint8 *out = (guint8 *)buffer; + char delimiter = '\0'; while (length && *in) { guint8 d1 = in[0], d2 = in[1]; @@ -2025,8 +2027,15 @@ nm_utils_hwaddr_aton_len (const char *asc, gpointer buffer, gsize length) length--; if (*in) { - if (*in != ':') - return NULL; + if (delimiter == '\0') { + if (*in == ':' || *in == '-') + delimiter = *in; + else + return NULL; + } else { + if (*in != delimiter) + return NULL; + } in++; } }