Fix nil dereference in server peerlist
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
DataHoarder 2024-02-25 22:16:52 +01:00
parent bd274f5ecd
commit cd26934d16
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk

View file

@ -242,7 +242,8 @@ func (s *Server) RemoveFromPeerList(ip netip.Addr) {
ip = ip.Unmap()
s.peerListLock.Lock()
defer s.peerListLock.Unlock()
for i, a := range s.peerList {
for i := len(s.peerList) - 1; i >= 0; i-- {
a := s.peerList[i]
if a.AddressPort.Addr().Compare(ip) == 0 {
s.peerList = slices.Delete(s.peerList, i, i+1)
return
@ -350,13 +351,13 @@ func (s *Server) UpdateClientConnections() {
deletedPeers++
}
}
peerList2 = peerList
peerList = peerList2
if deletedPeers > 0 {
func() {
s.peerListLock.Lock()
defer s.peerListLock.Unlock()
s.peerList = peerList
s.peerList = slices.Clone(peerList)
}()
}