From f5f94e665032951a42b7896b1cfe8f8670d507ca Mon Sep 17 00:00:00 2001 From: Mojtaba Date: Tue, 12 Dec 2023 12:01:10 +0100 Subject: [PATCH] fix: nil deref error in /services/status endpoint --- api/v1/net_services_status.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/api/v1/net_services_status.go b/api/v1/net_services_status.go index 7aa1a82..790f471 100644 --- a/api/v1/net_services_status.go +++ b/api/v1/net_services_status.go @@ -33,18 +33,24 @@ func (a *RESTApiV1) NetServicesStatus(resp http.ResponseWriter, req *http.Reques if s, ok := ns.service.(*packetloss.PacketLoss); ok { name = "packetloss" params["packet_loss_rate"] = s.PacketLossRate - netIfaceName = s.NetworkInterface.Name + if s.NetworkInterface != nil { + netIfaceName = s.NetworkInterface.Name + } } else if s, ok := ns.service.(*bandwidth.Bandwidth); ok { name = "bandwidth" params["limit"] = s.Limit - netIfaceName = s.NetworkInterface.Name + if s.NetworkInterface != nil { + netIfaceName = s.NetworkInterface.Name + } } else if s, ok := ns.service.(*latency.Latency); ok { name = "latency" params["latency_ms"] = s.Latency.Milliseconds() params["jitter_ms"] = s.Jitter.Milliseconds() - netIfaceName = s.NetworkInterface.Name + if s.NetworkInterface != nil { + netIfaceName = s.NetworkInterface.Name + } } else { sendJSONError(resp,