Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parse error for z_sender_sockaddr #4

Merged
merged 2 commits into from
Apr 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion notice.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,13 @@ func DecodeRawNotice(r *RawNotice) (*Notice, error) {

var senderAddress net.IP
if len(r.HeaderFields) > senderSockaddrIndex {
ipBytes, err := DecodeZcode(r.HeaderFields[senderSockaddrIndex])
sockaddrField := r.HeaderFields[senderSockaddrIndex]
var ipBytes []byte
if len(sockaddrField) != 0 && sockaddrField[0] == 'Z' {
ipBytes, err = DecodeZcode(sockaddrField)
} else {
ipBytes, err = DecodeZAscii(sockaddrField)
}
if err != nil {
return nil, err
}
Expand Down
12 changes: 10 additions & 2 deletions notice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,16 @@ func TestDecodeNotice(t *testing.T) {
}

// Value in sender address takes precedence over UID value.
raw.HeaderFields[17] = []byte("Z\x08\x08\x08\x08")
expected.SenderAddress = net.ParseIP("8.8.8.8").To4()
raw.HeaderFields[17] = []byte("Z\xDE\xAD\xBE\xEF")
expected.SenderAddress = net.ParseIP("222.173.190.239").To4()
if notice, err := DecodeRawNotice(raw); err != nil {
t.Errorf("DecodeRawNotice(%v) failed: %v", raw, err)
} else {
expectNoticesEqual(t, notice, expected)
}

raw.HeaderFields[17] = []byte("0xDEADBEEF")
expected.SenderAddress = net.ParseIP("222.173.190.239").To4()
if notice, err := DecodeRawNotice(raw); err != nil {
t.Errorf("DecodeRawNotice(%v) failed: %v", raw, err)
} else {
Expand Down
2 changes: 1 addition & 1 deletion raw_notice.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const (
multipartIndex // string
multiuidIndex // 12-byte zascii
// Added in 2009; no version bump
senderSockaddrIndex // zcode
senderSockaddrIndex // zcode or zascii
charsetIndex // zascii16 little-endian
// Other fields
numKnownFields
Expand Down