From 0f1ef9729f1a236abcfd6e478c7fbc8e3903dddb Mon Sep 17 00:00:00 2001 From: krawthekrow Date: Sun, 15 Apr 2018 20:47:28 -0400 Subject: [PATCH 1/2] fix parse error for z_sender_sockaddr --- notice.go | 8 +++++++- raw_notice.go | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/notice.go b/notice.go index af1c032..aa8818b 100644 --- a/notice.go +++ b/notice.go @@ -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 } diff --git a/raw_notice.go b/raw_notice.go index 7c37603..6e4ac4d 100644 --- a/raw_notice.go +++ b/raw_notice.go @@ -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 From aafaa1ad2b591781f0c8f8335ff1caa4b7c4db05 Mon Sep 17 00:00:00 2001 From: krawthekrow Date: Sun, 15 Apr 2018 23:26:51 -0400 Subject: [PATCH 2/2] add test for zascii SenderAddress in DecodeNotice, use different ip address to test endianness --- notice_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/notice_test.go b/notice_test.go index 29f574e..1c0b9c7 100644 --- a/notice_test.go +++ b/notice_test.go @@ -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 {