Skip to content

Commit 88a6421

Browse files
committed
dns/dnsmessage: avoid use of "strings" and "math" in dns/dnsmessage
dns/dnsmessage is used by the net package, which does not have strings and math in its permitted dependencies. Change-Id: I2b59887c59891dc61e49dd6430f3a72486ddd66a Reviewed-on: https://go-review.googlesource.com/c/net/+/723902 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Nicholas Husin <nsh@golang.org> Reviewed-by: Nicholas Husin <husin@google.com>
1 parent 123d099 commit 88a6421

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

dns/dnsmessage/svcb.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
package dnsmessage
66

77
import (
8-
"math"
98
"slices"
10-
"strings"
119
)
1210

1311
// An SVCBResource is an SVCB Resource record.
@@ -23,19 +21,18 @@ func (r *SVCBResource) realType() Type {
2321

2422
// GoString implements fmt.GoStringer.GoString.
2523
func (r *SVCBResource) GoString() string {
26-
var b strings.Builder
27-
b.WriteString("dnsmessage.SVCBResource{")
28-
b.WriteString("Priority: " + printUint16(r.Priority) + ", ")
29-
b.WriteString("Target: " + r.Target.GoString() + ", ")
30-
b.WriteString("Params: []dnsmessage.SVCParam{")
24+
b := []byte("dnsmessage.SVCBResource{" +
25+
"Priority: " + printUint16(r.Priority) + ", " +
26+
"Target: " + r.Target.GoString() + ", " +
27+
"Params: []dnsmessage.SVCParam{")
3128
if len(r.Params) > 0 {
32-
b.WriteString(r.Params[0].GoString())
29+
b = append(b, r.Params[0].GoString()...)
3330
for _, p := range r.Params[1:] {
34-
b.WriteString(", " + p.GoString())
31+
b = append(b, ", "+p.GoString()...)
3532
}
3633
}
37-
b.WriteString("}}")
38-
return b.String()
34+
b = append(b, "}}"...)
35+
return string(b)
3936
}
4037

4138
// An HTTPSResource is an HTTPS Resource record.
@@ -176,7 +173,7 @@ func (r *SVCBResource) pack(msg []byte, _ map[string]uint16, _ int) ([]byte, err
176173
if i > 0 && param.Key <= previousKey {
177174
return oldMsg, &nestedError{"SVCBResource.Params", errParamOutOfOrder}
178175
}
179-
if len(param.Value) > math.MaxUint16 {
176+
if len(param.Value) > (1<<16)-1 {
180177
return oldMsg, &nestedError{"SVCBResource.Params", errTooLongSVCBValue}
181178
}
182179
msg = packUint16(msg, uint16(param.Key))

0 commit comments

Comments
 (0)