]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: skip routing messages with mismatched version
authorJoel Sing <jsing@google.com>
Tue, 10 Dec 2013 13:03:46 +0000 (00:03 +1100)
committerJoel Sing <jsing@google.com>
Tue, 10 Dec 2013 13:03:46 +0000 (00:03 +1100)
Skip routing messages with a mismatched version, rather than failing
and returning EINVAL. Only return EINVAL if we were unable to parse
any of the routing messages (presumably due to a version mismatch).

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/30340043

src/pkg/syscall/route_bsd.go

index 638073592d5b910e729ec398c843943bb8eaef95..48af587450ba1eca15cbd56abc775c41f3c36670 100644 (file)
@@ -199,14 +199,21 @@ func (m *InterfaceAddrMessage) sockaddr() (sas []Sockaddr) {
 // ParseRoutingMessage parses b as routing messages and returns the
 // slice containing the RoutingMessage interfaces.
 func ParseRoutingMessage(b []byte) (msgs []RoutingMessage, err error) {
+       msgCount := 0
        for len(b) >= anyMessageLen {
+               msgCount++
                any := (*anyMessage)(unsafe.Pointer(&b[0]))
                if any.Version != RTM_VERSION {
-                       return nil, EINVAL
+                       b = b[any.Msglen:]
+                       continue
                }
                msgs = append(msgs, any.toRoutingMessage(b))
                b = b[any.Msglen:]
        }
+       // We failed to parse any of the messages - version mismatch?
+       if msgCount > 0 && len(msgs) == 0 {
+               return nil, EINVAL
+       }
        return msgs, nil
 }