diff options
author | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-07-04 09:40:40 +0200 |
---|---|---|
committer | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-07-04 13:06:01 +0200 |
commit | c333b3ee569dbf5a2fafd34a255fce35eeb0653c (patch) | |
tree | cb97037444b2d0a5c0d1307cbb3278c6a0edeee9 /ogcp/views.py | |
parent | 320df7ec0caea969fdcce717b84c31afc6194015 (diff) |
views: check invalid values in prettify_mac()
Return without modification if the MAC is not valid.
Diffstat (limited to 'ogcp/views.py')
-rw-r--r-- | ogcp/views.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/ogcp/views.py b/ogcp/views.py index ae07f31..a2c4e9d 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -99,9 +99,6 @@ class ServerErrorCode(Exception): def normalize_mac(mac): return mac.replace(':', '').replace('-', '').replace('.', '').lower() -def prettify_mac(mac): - return (':'.join(mac[i:i+2] for i in range(0, 12, 2))).lower() - def is_valid_normalized_mac(mac): if len(mac) != 12: return False @@ -109,6 +106,13 @@ def is_valid_normalized_mac(mac): return False return True +def prettify_mac(mac): + normalized_mac = normalize_mac(mac) + + if not is_valid_normalized_mac(normalized_mac): + return mac + return (':'.join(normalized_mac[i:i+2] for i in range(0, 12, 2))).lower() + def ogserver_down(view): flash(_('Cannot talk to ogserver. Is ogserver down?'), category='error') return redirect(url_for(view)) |