Skip to content

Commit

Permalink
Allocate 6 bytes to copy MAC addresses when unmarshalling ethernet ma…
Browse files Browse the repository at this point in the history
…tch fields

Currently we are trying to unmarshal data to an uninitialized struct whose
net.HardwareAddr fields are set to nil. In this case the copy() function
silently does nothing.

Initialize the fields to slices of bytes of length 6 before copying data to them.

This commit is derived from antrea-io#30.

Signed-off-by: shi0rik0 <[email protected]>
  • Loading branch information
shi0rik0 committed Jul 11, 2023
1 parent f52e481 commit 58ae9eb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions openflow13/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ func (m *EthDstField) MarshalBinary() (data []byte, err error) {
}

func (m *EthDstField) UnmarshalBinary(data []byte) error {
m.EthDst = make([]byte, 6)
copy(m.EthDst, data)
return nil
}
Expand Down Expand Up @@ -700,6 +701,7 @@ func (m *EthSrcField) MarshalBinary() (data []byte, err error) {
}

func (m *EthSrcField) UnmarshalBinary(data []byte) error {
m.EthSrc = make([]byte, 6)
copy(m.EthSrc, data)
return nil
}
Expand Down
2 changes: 2 additions & 0 deletions openflow15/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,7 @@ func (m *EthDstField) MarshalBinary() (data []byte, err error) {
}

func (m *EthDstField) UnmarshalBinary(data []byte) error {
m.EthDst = make([]byte, 6)
copy(m.EthDst, data)
return nil
}
Expand Down Expand Up @@ -899,6 +900,7 @@ func (m *EthSrcField) MarshalBinary() (data []byte, err error) {
}

func (m *EthSrcField) UnmarshalBinary(data []byte) error {
m.EthSrc = make([]byte, 6)
copy(m.EthSrc, data)
return nil
}
Expand Down

0 comments on commit 58ae9eb

Please sign in to comment.