mirror of
https://github.com/golang/net.git
synced 2026-03-31 18:37:08 +09:00
dns/dnsmessage: return an error for too long SVCParam.Value
Updates #43790 Change-Id: Id9f5bdc3e17a6f7d2c9b7b8a4e48c0c66a6a6964 Reviewed-on: https://go-review.googlesource.com/c/net/+/712080 Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Vinicius Fortuna <fortuna@google.com> Reviewed-by: Sean Liao <sean@liao.dev> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
committed by
Gopher Robot
parent
3ba82d21c9
commit
ef82ae896f
@@ -291,6 +291,7 @@ var (
|
||||
errNonCanonicalName = errors.New("name is not in canonical format (it must end with a .)")
|
||||
errStringTooLong = errors.New("character string exceeds maximum length (255)")
|
||||
errParamOutOfOrder = errors.New("parameter out of order")
|
||||
errTooLongSVCBValue = errors.New("value too long (>65535 bytes)")
|
||||
)
|
||||
|
||||
// Internal constants.
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
package dnsmessage
|
||||
|
||||
import (
|
||||
"math"
|
||||
"slices"
|
||||
"strings"
|
||||
)
|
||||
@@ -171,6 +172,9 @@ func (r *SVCBResource) pack(msg []byte, compression map[string]uint16, compressi
|
||||
if i > 0 && param.Key <= previousKey {
|
||||
return oldMsg, &nestedError{"SVCBResource.Params", errParamOutOfOrder}
|
||||
}
|
||||
if len(param.Value) > math.MaxUint16 {
|
||||
return oldMsg, &nestedError{"SVCBResource.Params", errTooLongSVCBValue}
|
||||
}
|
||||
msg = packUint16(msg, uint16(param.Key))
|
||||
msg = packUint16(msg, uint16(len(param.Value)))
|
||||
msg = append(msg, param.Value...)
|
||||
|
||||
@@ -6,6 +6,7 @@ package dnsmessage
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"math"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
@@ -364,3 +365,29 @@ func TestSVCBWireFormat(t *testing.T) {
|
||||
}
|
||||
testRecord(bytes, parsed)
|
||||
}
|
||||
|
||||
func TestSVCBPackLongValue(t *testing.T) {
|
||||
b := NewBuilder(nil, Header{})
|
||||
b.StartQuestions()
|
||||
b.StartAnswers()
|
||||
|
||||
res := SVCBResource{
|
||||
Target: MustNewName("example.com."),
|
||||
Params: []SVCParam{
|
||||
{
|
||||
Key: SVCParamMandatory,
|
||||
Value: make([]byte, math.MaxUint16+1),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err := b.SVCBResource(ResourceHeader{Name: MustNewName("example.com.")}, res)
|
||||
if err == nil || err.Error() != "ResourceBody: SVCBResource.Params: value too long (>65535 bytes)" {
|
||||
t.Fatalf(`b.SVCBResource() = %v; want = "ResourceBody: SVCBResource.Params: value too long (>65535 bytes)"`, err)
|
||||
}
|
||||
|
||||
err = b.HTTPSResource(ResourceHeader{Name: MustNewName("example.com.")}, HTTPSResource{res})
|
||||
if err == nil || err.Error() != "ResourceBody: SVCBResource.Params: value too long (>65535 bytes)" {
|
||||
t.Fatalf(`b.HTTPSResource() = %v; want = "ResourceBody: SVCBResource.Params: value too long (>65535 bytes)"`, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user