mirror of
https://github.com/golang/go
synced 2024-11-23 08:00:05 -07:00
net: fix LookupTXT of long records on Windows
The response to a TXT lookup is a sequence of RRs, each of which contains a sequence of string fragments. The correct handling of the response is to do: for each rr { list = append(list, strings.Join(rr.fragments, "")) } (like in at dnsRR_TXT.Walk, used on most platforms). The Windows code incorrectly does: for each rr { list = append(list, rr.fragments...) } This CL fixes it to concatenate fragments, as it must. Fixes #21472. Change-Id: I78cce96f172e5e90da9a212b0343457f6d5f92e8 Reviewed-on: https://go-review.googlesource.com/79555 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
571ee0436f
commit
b6cf58d5b8
@ -9,7 +9,9 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"internal/testenv"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@ -303,6 +305,25 @@ func TestLookupGoogleHost(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLookupLongTXT(t *testing.T) {
|
||||
if testenv.Builder() == "" {
|
||||
testenv.MustHaveExternalNetwork(t)
|
||||
}
|
||||
|
||||
txts, err := LookupTXT("golang.rsc.io")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sort.Strings(txts)
|
||||
want := []string{
|
||||
strings.Repeat("abcdefghijklmnopqrstuvwxyABCDEFGHJIKLMNOPQRSTUVWXY", 10),
|
||||
"gophers rule",
|
||||
}
|
||||
if !reflect.DeepEqual(txts, want) {
|
||||
t.Fatalf("LookupTXT golang.rsc.io incorrect\nhave %q\nwant %q", txts, want)
|
||||
}
|
||||
}
|
||||
|
||||
var lookupGoogleIPTests = []struct {
|
||||
name string
|
||||
}{
|
||||
|
@ -279,10 +279,11 @@ func (*Resolver) lookupTXT(ctx context.Context, name string) ([]string, error) {
|
||||
txts := make([]string, 0, 10)
|
||||
for _, p := range validRecs(r, syscall.DNS_TYPE_TEXT, name) {
|
||||
d := (*syscall.DNSTXTData)(unsafe.Pointer(&p.Data[0]))
|
||||
s := ""
|
||||
for _, v := range (*[1 << 10]*uint16)(unsafe.Pointer(&(d.StringArray[0])))[:d.StringCount] {
|
||||
s := syscall.UTF16ToString((*[1 << 20]uint16)(unsafe.Pointer(v))[:])
|
||||
txts = append(txts, s)
|
||||
s += syscall.UTF16ToString((*[1 << 20]uint16)(unsafe.Pointer(v))[:])
|
||||
}
|
||||
txts = append(txts, s)
|
||||
}
|
||||
return txts, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user