From c333b3ee569dbf5a2fafd34a255fce35eeb0653c Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Thu, 4 Jul 2024 09:40:40 +0200 Subject: views: check invalid values in prettify_mac() Return without modification if the MAC is not valid. --- ogcp/views.py | 10 +++++++--- 1 file 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)) -- cgit v1.2.3-18-g5258