Commit 8fb00704 authored by Iustin Pop's avatar Iustin Pop

Fix mac checker regex

Currently, the mac checker regex could match a corner case of
11:22:33:44:55:66: (one extra colon at the end). We fix this, and we
also move the regex compilation outside of this function, at module
level.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent d4068f64
......@@ -92,6 +92,9 @@ _STRUCT_UCRED_SIZE = struct.calcsize(_STRUCT_UCRED)
_MCL_CURRENT = 1
_MCL_FUTURE = 2
#: MAC checker regexp
_MAC_CHECK = re.compile("^([0-9a-f]{2}:){5}[0-9a-f]{2}$", re.I)
class RunResult(object):
"""Holds the result of running external programs.
......@@ -1697,8 +1700,7 @@ def NormalizeAndValidateMac(mac):
@raise errors.OpPrereqError: If the MAC isn't valid
"""
mac_check = re.compile("^([0-9a-f]{2}(:|$)){6}$", re.I)
if not mac_check.match(mac):
if not _MAC_CHECK.match(mac):
raise errors.OpPrereqError("Invalid MAC address specified: %s" %
mac, errors.ECODE_INVAL)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment