Skip to content

Commit e4fd2fe

Browse files
committed
internal/message: Be more tolerant with the number of system addresses.
1 parent c7f5c8f commit e4fd2fe

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

internal/message/connection_request_accepted.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,16 @@ func (pk *ConnectionRequestAccepted) UnmarshalBinary(data []byte) error {
2525
pk.SystemIndex = binary.BigEndian.Uint16(data[offset:])
2626
offset += 2
2727
for i := range 20 {
28-
if len(data) < addrSize(data[offset:]) {
28+
if len(data[offset:]) == 16 {
29+
// Some implementations send fewer system addresses.
30+
break
31+
}
32+
if len(data[offset:]) < addrSize(data[offset:]) {
2933
return io.ErrUnexpectedEOF
3034
}
3135
address, n := addr(data[offset:])
3236
pk.SystemAddresses[i] = address
3337
offset += n
34-
35-
if len(data[offset:]) == 16 {
36-
// Some implementations send only 10 system addresses.
37-
break
38-
}
3938
}
4039
if len(data[offset:]) < 16 {
4140
return io.ErrUnexpectedEOF

internal/message/new_incoming_connection.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,16 @@ func (pk *NewIncomingConnection) UnmarshalBinary(data []byte) error {
2222
var offset int
2323
pk.ServerAddress, offset = addr(data)
2424
for i := range 20 {
25-
if len(data) < addrSize(data[offset:]) {
25+
if len(data[offset:]) == 16 {
26+
// Some implementations send only 10 system addresses.
27+
break
28+
}
29+
if len(data[offset:]) < addrSize(data[offset:]) {
2630
return io.ErrUnexpectedEOF
2731
}
2832
address, n := addr(data[offset:])
2933
pk.SystemAddresses[i] = address
3034
offset += n
31-
32-
if len(data[offset:]) == 16 {
33-
// Some implementations send only 10 system addresses.
34-
break
35-
}
3635
}
3736
if len(data[offset:]) < 16 {
3837
return io.ErrUnexpectedEOF

0 commit comments

Comments
 (0)