From 2b74170c41137b5ee7c989b8de504da92deedb15 Mon Sep 17 00:00:00 2001 From: tfromme Date: Sun, 12 Dec 2021 23:07:42 -0500 Subject: [PATCH] Fix potential MacAddressField crash in DRF Using the MACAddressField on a model, then attempting to submit an "extra large" mac address such as `be:ef:be:ef:be:ef:be:ef` results in an IndexError, which gets bubbled out of DRF and results in a 500 ServerError. This should raise a ValidationError instead. --- netfields/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netfields/forms.py b/netfields/forms.py index e1e4e1d..effb6e3 100644 --- a/netfields/forms.py +++ b/netfields/forms.py @@ -108,7 +108,7 @@ def to_python(self, value): try: return EUI(value, dialect=mac_unix_common) - except (AddrFormatError, TypeError): + except (AddrFormatError, IndexError, TypeError): raise ValidationError(self.error_messages['invalid']) def widget_attrs(self, widget):