From 14effdfbe84e895048bfbe73bbee6c2feaa0d172 Mon Sep 17 00:00:00 2001 From: xuxiaochuang Date: Thu, 22 Jul 2021 20:29:42 +0800 Subject: [PATCH] fix: some pad's length in UnmarshalBinary is 0 Signed-off-by: xuxiaochuang --- openflow13/multipart.go | 10 +++++----- openflow13/openflow13.go | 4 +++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/openflow13/multipart.go b/openflow13/multipart.go index f5e3fb1..8642d8f 100644 --- a/openflow13/multipart.go +++ b/openflow13/multipart.go @@ -668,9 +668,9 @@ func (s *TableStats) UnmarshalBinary(data []byte) error { s.TableId = data[0] n += 1 copy(s.pad, data[n:]) - n += len(s.pad) + n += 3 copy(s.Name, data[n:]) - n += len(s.Name) + n += MAX_TABLE_NAME_LEN s.Wildcards = binary.BigEndian.Uint32(data[n:]) n += 4 s.MaxEntries = binary.BigEndian.Uint32(data[n:]) @@ -790,7 +790,7 @@ func (s *PortStats) UnmarshalBinary(data []byte) error { s.PortNo = binary.BigEndian.Uint16(data[n:]) n += 2 copy(s.pad, data[n:]) - n += len(s.pad) + n += 6 s.RxPackets = binary.BigEndian.Uint64(data[n:]) n += 8 s.TxPackets = binary.BigEndian.Uint64(data[n:]) @@ -895,7 +895,7 @@ func (s *QueueStats) UnmarshalBinary(data []byte) error { s.PortNo = binary.BigEndian.Uint16(data[n:]) n += 2 copy(s.pad, data[n:]) - n += len(s.pad) + n += 2 s.QueueId = binary.BigEndian.Uint32(data[n:]) n += 4 s.TxBytes = binary.BigEndian.Uint64(data[n:]) @@ -952,7 +952,7 @@ func (s *PortStatus) UnmarshalBinary(data []byte) error { s.Reason = data[n] n += 1 copy(s.pad, data[n:]) - n += len(s.pad) + n += 7 err = s.Desc.UnmarshalBinary(data[n:]) return err diff --git a/openflow13/openflow13.go b/openflow13/openflow13.go index aa0128b..07ba6af 100644 --- a/openflow13/openflow13.go +++ b/openflow13/openflow13.go @@ -270,7 +270,8 @@ func (p *PacketOut) UnmarshalBinary(data []byte) error { n += 6 // for pad - for n < (n + p.ActionsLen) { + actionsBound := n + p.ActionsLen + for n < actionsBound { a, err := DecodeAction(data[n:]) if err != nil { return err @@ -745,6 +746,7 @@ func (s *SwitchFeatures) UnmarshalBinary(data []byte) error { for next < len(data) { p := NewPhyPort() err = p.UnmarshalBinary(data[next:]) + s.Ports = append(s.Ports, *p) next += int(p.Len()) } return err