openwisp / netdiff

Python library for parsing network topology data (e.g.: OpenVPN, Wireguard, ZeroTier, NetJSON, Dynamic Routing Protocols) and detect changes.
MIT License
80 stars 37 forks source link

[bug] Wireguard allowed_ips may be None #104

Closed nemesifier closed 2 years ago

nemesifier commented 2 years ago

It seems that in some rare cases the allowed_ips may be None, but the library doesn't handle this right now:

AttributeError: 'NoneType' object has no attribute 'split'
  File "django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "django/views/generic/base.py", line 84, in view
    return self.dispatch(request, *args, **kwargs)
  File "rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "openwisp_network_topology/api/views.py", line 137, in post
    topology.receive(request.data)
  File "openwisp_network_topology/base/topology.py", line 364, in receive
    self.update(data)
  File "openwisp_network_topology/base/topology.py", line 295, in update
    diff = self.diff(data)
  File "openwisp_network_topology/base/topology.py", line 138, in diff
    latest = self.get_topology_data(data)
  File "openwisp_network_topology/base/topology.py", line 119, in get_topology_data
    latest = self.parser_class(data=data, url=self.url, timeout=TIMEOUT)
  File "netdiff/parsers/base.py", line 72, in __init__
    self.original_data = self.to_python(data)
  File "netdiff/parsers/wireguard.py", line 20, in to_python
    return self._wg_dump_to_python(e.data)
  File "netdiff/parsers/wireguard.py", line 28, in _wg_dump_to_python
    parsed_lines = self._parse_lines(lines)
  File "netdiff/parsers/wireguard.py", line 74, in _parse_lines
    allowed_ips=allowed_ips.split(','),