From 45e481ce445dbbfdb04c7797c204f81c6c44844e Mon Sep 17 00:00:00 2001 From: Tom Thorogood Date: Thu, 27 Sep 2018 16:17:48 +0930 Subject: [PATCH] Fix unpackString bug: 127 DEL is unprintable (#755) This case previously differed from UnpackDomainName in msg.go and both sprintTxtOctet and appendTXTStringByte in types.go and was incorrect. --- msg_helpers.go | 2 +- msg_helpers_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/msg_helpers.go b/msg_helpers.go index e8c6b745..d58ff1d7 100644 --- a/msg_helpers.go +++ b/msg_helpers.go @@ -275,7 +275,7 @@ func unpackString(msg []byte, off int) (string, int, error) { case b == '"' || b == '\\': s.WriteByte('\\') s.WriteByte(b) - case b < 32 || b > 127: // unprintable + case b < ' ' || b > '~': // unprintable var buf [3]byte bufs := strconv.AppendInt(buf[:0], int64(b), 10) s.WriteByte('\\') diff --git a/msg_helpers_test.go b/msg_helpers_test.go index df1fbfae..ebeac84d 100644 --- a/msg_helpers_test.go +++ b/msg_helpers_test.go @@ -108,7 +108,7 @@ func TestPackDataNsec(t *testing.T) { } func TestUnpackString(t *testing.T) { - msg := []byte("\x00abcdef\x0f\\\"ghi\x04mmm") + msg := []byte("\x00abcdef\x0f\\\"ghi\x04mmm\x7f") msg[0] = byte(len(msg) - 1) got, _, err := unpackString(msg, 0) @@ -116,7 +116,7 @@ func TestUnpackString(t *testing.T) { t.Fatal(err) } - if want := `abcdef\015\\\"ghi\004mmm`; want != got { + if want := `abcdef\015\\\"ghi\004mmm\127`; want != got { t.Errorf("expected %q, got %q", want, got) } }