diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-02-16 10:52:55 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-02-16 10:52:55 +0900 |
commit | d7253516a40801c7dcca553ffe244ccb0994116e (patch) | |
tree | c2649a7f27cb023fb6e7f11b10844399ff9a6da6 | |
parent | 560fa6cbd5c6ddb8fcd5c262b720459c064a9b23 (diff) |
server: check the bgp message length before sending
if the length is over 4096, the message will be dropped.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | packet/bgp.go | 3 | ||||
-rw-r--r-- | server/fsm.go | 13 |
2 files changed, 14 insertions, 2 deletions
diff --git a/packet/bgp.go b/packet/bgp.go index aa76cb12..79f62978 100644 --- a/packet/bgp.go +++ b/packet/bgp.go @@ -2734,6 +2734,9 @@ func (msg *BGPMessage) Serialize() ([]byte, error) { return nil, err } if msg.Header.Len == 0 { + if 19 + len(b) > BGP_MAX_MESSAGE_LENGTH { + return nil, NewMessageError(0, 0, nil, fmt.Sprintf("too long message length %d", 19 + len(b))) + } msg.Header.Len = 19 + uint16(len(b)) } h, err := msg.Header.Serialize() diff --git a/server/fsm.go b/server/fsm.go index 4649ef85..f66e8f57 100644 --- a/server/fsm.go +++ b/server/fsm.go @@ -567,8 +567,17 @@ func (h *FSMHandler) sendMessageloop() error { // sending notification, we'll die. select { case m := <-h.outgoing: - b, _ := m.Serialize() - _, err := conn.Write(b) + b, err := m.Serialize() + if err != nil { + log.WithFields(log.Fields{ + "Topic": "Peer", + "Key": fsm.peerConfig.NeighborAddress, + "Data": err, + }).Warn("failed to serialize") + fsm.bgpMessageStateUpdate(0, false) + continue + } + _, err = conn.Write(b) if err != nil { h.errorCh <- true return nil |