Ver Fonte

pkg/route: filter invalid route updates

This commit fixes the underlying issue that caused crashes when
receiving a nil route update, as reported in
https://github.com/squat/kilo/issues/17.
Lucas Servén Marín há 6 anos atrás
pai
commit
1265ce0cd5
1 ficheiros alterados com 4 adições e 0 exclusões
  1. 4 0
      pkg/route/route.go

+ 4 - 0
pkg/route/route.go

@@ -91,6 +91,10 @@ func (t *Table) Run(stop <-chan struct{}) (<-chan error, error) {
 			case unix.RTM_DELROUTE:
 			case unix.RTM_DELROUTE:
 				t.mu.Lock()
 				t.mu.Lock()
 				for _, r := range t.routes {
 				for _, r := range t.routes {
+					// Filter out invalid routes.
+					if r == nil || r.Dst == nil {
+						continue
+					}
 					// If any deleted route's destination matches a destination
 					// If any deleted route's destination matches a destination
 					// in the table, reset the corresponding route just in case.
 					// in the table, reset the corresponding route just in case.
 					if r.Dst.IP.Equal(e.Route.Dst.IP) && r.Dst.Mask.String() == e.Route.Dst.Mask.String() {
 					if r.Dst.IP.Equal(e.Route.Dst.IP) && r.Dst.Mask.String() == e.Route.Dst.Mask.String() {