Skip to content

Commit

Permalink
internal/message: Be more tolerant with the number of system addresses.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandertv committed Jun 21, 2024
1 parent c7f5c8f commit e4fd2fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
11 changes: 5 additions & 6 deletions internal/message/connection_request_accepted.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@ func (pk *ConnectionRequestAccepted) UnmarshalBinary(data []byte) error {
pk.SystemIndex = binary.BigEndian.Uint16(data[offset:])
offset += 2
for i := range 20 {
if len(data) < addrSize(data[offset:]) {
if len(data[offset:]) == 16 {
// Some implementations send fewer system addresses.
break
}
if len(data[offset:]) < addrSize(data[offset:]) {
return io.ErrUnexpectedEOF
}
address, n := addr(data[offset:])
pk.SystemAddresses[i] = address
offset += n

if len(data[offset:]) == 16 {
// Some implementations send only 10 system addresses.
break
}
}
if len(data[offset:]) < 16 {
return io.ErrUnexpectedEOF
Expand Down
11 changes: 5 additions & 6 deletions internal/message/new_incoming_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,16 @@ func (pk *NewIncomingConnection) UnmarshalBinary(data []byte) error {
var offset int
pk.ServerAddress, offset = addr(data)
for i := range 20 {
if len(data) < addrSize(data[offset:]) {
if len(data[offset:]) == 16 {
// Some implementations send only 10 system addresses.
break
}
if len(data[offset:]) < addrSize(data[offset:]) {
return io.ErrUnexpectedEOF
}
address, n := addr(data[offset:])
pk.SystemAddresses[i] = address
offset += n

if len(data[offset:]) == 16 {
// Some implementations send only 10 system addresses.
break
}
}
if len(data[offset:]) < 16 {
return io.ErrUnexpectedEOF
Expand Down

0 comments on commit e4fd2fe

Please sign in to comment.