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.
This commit is contained in:
Tom Thorogood 2018-09-27 16:17:48 +09:30 committed by Miek Gieben
parent 7482521355
commit 45e481ce44
2 changed files with 3 additions and 3 deletions

View File

@ -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('\\')

View File

@ -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)
}
}