51 Commits

Author SHA1 Message Date
Steven Richards
dec6603c16 dns/dnsmessage: reject too large of names early during unpack
The existing implementation of the Name.unpack method does not check the
length of the domain name until parsing is complete. This allows a
malicious user to supply an unreasonably large name and wastle cycles
parsing. This change moves an equivalent check into the loop during
process to short-circuit if we've created too large of a name.

For golang/go#77540

Change-Id: I4c4bf20c0342825a09cefd9b0b3c0bdce0c80137
Reviewed-on: https://go-review.googlesource.com/c/net/+/750260
Reviewed-by: Roland Shoemaker <roland@golang.org>
Auto-Submit: Roland Shoemaker <roland@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2026-03-06 10:52:24 -08:00
Damien Neil
88a642172c 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>
2025-11-24 14:33:11 -08:00
Vinicius Fortuna
dec9fe711e dns/dnsmessage: update SVCB packing to prohibit name compression
This commit updates the dns/dnsmessage package to correctly handle SVCB record
packing by prohibiting name compression for the Target field.

It turns out the compression of names in RDATA is prohibited (see
https://datatracker.ietf.org/doc/html/rfc3597#section-4), except for well-known record
types (those defined in https://datatracker.ietf.org/doc/html/rfc1035).

The SVCB RFC actually explicitly calls that out
(https://datatracker.ietf.org/doc/html/rfc9460#section-2.2), so it was an oversight
in my part in https://go.dev/cl/710736.

Updates golang/go#43790

Change-Id: I287b034c9e01b49264e07e23293bacd830ab1832
GitHub-Last-Rev: 1d16664c57
GitHub-Pull-Request: golang/net#242
Reviewed-on: https://go-review.googlesource.com/c/net/+/713900
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Vinicius Fortuna <fortuna@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Sean Liao <sean@liao.dev>
Reviewed-by: Sean Liao <sean@liao.dev>
2025-10-23 13:39:34 -07:00
Mateusz Poliwczak
ef82ae896f 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>
2025-10-15 14:03:36 -07:00
Vinicius Fortuna
bb2055dafd dns/dnsmessage: add https svcb dns types
This change implements the proposal to add new DNS message types HTTPS and
SVCB in the golang.org/x/net/dns/dnsmessage package, as described in
golang/go#43790.

The implementation includes:
- New types TypeHTTPS and TypeSVCB.
- SVCBResource and HTTPSResource structs, with HTTPSResource embedding
  SVCBResource.
- SVCParam and SVCParamKey types for handling service parameters.
- pack and unpack methods for the new resource types.
- Integration into the Parser and Builder.
- Comprehensive tests, including for parameter handling logic.

I implemented the SVCB parsing code so that it performs only two
allocations: one for the []SVCParam slice, and one to hold the SVCParam
values. A test was added to demonstrate that.

Fixes golang/go#43790

Change-Id: I60439772fe0e339ae3141bd1dd9829564efe0f2a
GitHub-Last-Rev: 49c2ac0102
GitHub-Pull-Request: golang/net#241
Reviewed-on: https://go-review.googlesource.com/c/net/+/710736
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Vinicius Fortuna <fortuna@google.com>
2025-10-15 07:15:29 -07:00
Damien Neil
c1f5833288 all: replace deprecated io/ioutil calls
The io/ioutil package's features were moved to
the io and os packages in Go 1.16.

x/net depends on Go 1.18. Drop ioutil calls,
so gopls doesn't warn about them.

Change-Id: Ibdb576d94f250808ae285aa142e2fd41e7e9afc9
Reviewed-on: https://go-review.googlesource.com/c/net/+/586244
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-05-21 19:59:00 +00:00
vitalmotif
ebc8168ac8 all: fix some typos
Change-Id: I7e2c867efcc960553da77e395b0069ab6776cd9f
GitHub-Last-Rev: eaa122d1b6
GitHub-Pull-Request: golang/net#205
Reviewed-on: https://go-review.googlesource.com/c/net/+/572995
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
2024-03-21 09:28:29 +00:00
Mateusz Poliwczak
73e4b50dad dns/dnsmessage: allow name compression for SRV resource parsing
As per RFC 3597:

Receiving servers MUST decompress domain names in RRs of well-known
   type, and SHOULD also decompress RRs of type RP, AFSDB, RT, SIG, PX,
   NXT, NAPTR, and SRV (although the current specification of the SRV RR
   in RFC2782 prohibits compression, RFC2052 mandated it, and some
   servers following that earlier specification are still in use).

This change allows SRV resource decompression.

Updates golang/go#36718
Updates golang/go#37362

Change-Id: I473c0d3803758e5b12886f378d2ed54bd5392144
GitHub-Last-Rev: 88d2e0642a
GitHub-Pull-Request: golang/net#199
Reviewed-on: https://go-review.googlesource.com/c/net/+/540375
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
2024-02-03 00:07:12 +00:00
Mateusz Poliwczak
92728b3b3c dns/dnsmessage: document that Skip does not fully validate the header
The Skip methods do not fully validate the name in header,
the compression pointers are not followed

Change-Id: If34a041d799a22117afac9bd23e76606f5d0c8f7
GitHub-Last-Rev: f8f2586fb2
GitHub-Pull-Request: golang/net#196
Reviewed-on: https://go-review.googlesource.com/c/net/+/534175
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-10-11 16:52:37 +00:00
Mateusz Poliwczak
7c40cbd800 dns/dnsmessage: use map[string]uint16 instead of map[string]int
The compression pointer is limited to 14 bits, so there is no
need to use int, uint16 is fine.

Change-Id: I2276cbf63761e26a7e8590f0337930db87895ea5
GitHub-Last-Rev: e04b451a63
GitHub-Pull-Request: golang/net#192
Reviewed-on: https://go-review.googlesource.com/c/net/+/528955
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Mateusz Poliwczak <mpoliwczak34@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-09-20 18:08:02 +00:00
Mateusz Poliwczak
94087adbf6 dns/dnsmessage: mention that Name in non-escaped
Change-Id: I090dea04d6007dc985d89270d0138f822dc7a10b
GitHub-Last-Rev: c604beebc1
GitHub-Pull-Request: golang/net#176
Reviewed-on: https://go-review.googlesource.com/c/net/+/500295
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-05 21:19:02 +00:00
Mateusz Poliwczak
b4d09be751 dns/dnsmessage: compress all names while appending to a buffer
Change-Id: Iedccbf3e47a63b2239def189ab41bab18a64c398
GitHub-Last-Rev: eb23195734
GitHub-Pull-Request: golang/net#189
Reviewed-on: https://go-review.googlesource.com/c/net/+/522575
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Mateusz Poliwczak <mpoliwczak34@gmail.com>
Reviewed-by: Joedian Reid <joedian@golang.org>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
2023-08-29 22:02:17 +00:00
Mateusz Poliwczak
efb8d7ab94 dns/dnsmessage: don't include bytes after name.Length in the compression map
This improves the performance of name compression and makes
the name.Data[name.Length:] not included in the compression
map, it is unnecessary and might cause issues (i.e. reusing
the Name struct, without using the NewName function).

goos: linux
goarch: amd64
pkg: golang.org/x/net/dns/dnsmessage
cpu: Intel(R) Core(TM) i5-4200M CPU @ 2.50GHz
             │    before     │                after                 │
             │    sec/op     │    sec/op     vs base                │
Pack-4         15.672µ ± 13%   5.470µ ± 14%  -65.10% (p=0.000 n=10)
AppendPack-4   15.144µ ± 12%   5.330µ ± 10%  -64.80% (p=0.000 n=10)
geomean         15.41µ         5.400µ        -64.95%

             │    before    │                after                 │
             │     B/op     │     B/op      vs base                │
Pack-4         6.051Ki ± 0%   1.285Ki ± 0%  -78.76% (p=0.000 n=10)
AppendPack-4    5684.0 ± 0%     804.0 ± 0%  -85.86% (p=0.000 n=10)
geomean        5.795Ki        1.005Ki       -82.67%

             │   before   │               after                │
             │ allocs/op  │ allocs/op   vs base                │
Pack-4         21.00 ± 0%   11.00 ± 0%  -47.62% (p=0.000 n=10)
AppendPack-4   20.00 ± 0%   10.00 ± 0%  -50.00% (p=0.000 n=10)
geomean        20.49        10.49       -48.82%

Change-Id: Idf40d5d4790d37eb7253214f089eff859a937c60
GitHub-Last-Rev: a3182830e2
GitHub-Pull-Request: golang/net#190
Reviewed-on: https://go-review.googlesource.com/c/net/+/522817
Run-TryBot: Mateusz Poliwczak <mpoliwczak34@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-08-28 16:23:47 +00:00
Damien Neil
0f7767ccf4 dns/dnsmessage: validate cached section when skipping sections
When skipping a section when p.resHeaderValid is set, verify
that the cached resource header is for the right section.

Fixes golang/go#62220

Change-Id: I8731dfdb5ad3cca94221b58f8be830bd2e16cff3
Reviewed-on: https://go-review.googlesource.com/c/net/+/521995
Reviewed-by: Mateusz Poliwczak <mpoliwczak34@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-08-23 20:18:28 +00:00
Mateusz Poliwczak
f89417cca1 dns/dnsmessage: reduce Parser size
In the net package the Parser is copied a lot, the
size of the Parser can be reduced easily by not storing the
entire ResourceHeader in the Parser.

It reduces the size from 328B to 80B.

Also it makes sure that the resource header parsing
methods don't return stale headers (from different
sections).

Change-Id: If05b03ba654ca5c03d536e86446c5a2a7dc79ec3
GitHub-Last-Rev: dacd25cc35
GitHub-Pull-Request: golang/net#186
Reviewed-on: https://go-review.googlesource.com/c/net/+/514855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Mateusz Poliwczak <mpoliwczak34@gmail.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
2023-08-22 20:47:50 +00:00
Mateusz Poliwczak
95cb3bb9eb dns/dnsmessage: show AD and CD bit in Header.GoString()
Change-Id: I7b973d255ec4ab1e1c0f8539b811ddc0503c2f48
GitHub-Last-Rev: 954434b621
GitHub-Pull-Request: golang/net#188
Reviewed-on: https://go-review.googlesource.com/c/net/+/521075
Run-TryBot: Mateusz Poliwczak <mpoliwczak34@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
2023-08-19 23:29:34 +00:00
Mateusz Poliwczak
d8f9c0143e dns/dnsmessage: add fuzz test
After CL 443215 pack(unpack(msg)) should never fail,
so we can add a fuzz test to prove that.

Change-Id: Ia2abfc30e2b2a492b4dd5de6ca6f29d2324bd737
GitHub-Last-Rev: 1d9812a34c
GitHub-Pull-Request: golang/net#177
Reviewed-on: https://go-review.googlesource.com/c/net/+/500296
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Joedian Reid <joedian@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Mateusz Poliwczak <mpoliwczak34@gmail.com>
2023-07-07 17:38:37 +00:00
Mateusz Poliwczak
81261084d0 dns/dnsmessage: update Parser docs
The current API returns ErrSectionDone, not (nil,nil).

Change-Id: I95c721c6c198e7302b9154bc39617b502e3d62f9
GitHub-Last-Rev: c66bcff3b1
GitHub-Pull-Request: golang/net#181
Reviewed-on: https://go-review.googlesource.com/c/net/+/507955
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
2023-07-07 01:47:36 +00:00
Mateusz Poliwczak
ca96da6018 dns/dnsmessage: reject names with dots inside label
Fixes golang/go#56246

Change-Id: I9c8d611d1305536a7510bf6c4a02a5e551aa657a
GitHub-Last-Rev: 8a8703a1a7
GitHub-Pull-Request: golang/net#154
Reviewed-on: https://go-review.googlesource.com/c/net/+/443215
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Mateusz Poliwczak <mpoliwczak34@gmail.com>
Auto-Submit: Roland Shoemaker <roland@golang.org>
2023-05-24 18:47:04 +00:00
Mateusz Poliwczak
2b0b97d53f dns/dnsmessage: reject packing of 255B rooted names, reject unpacking of 256B (dns encoded) names
Packing a 255B (rooted) name will create an 256B (dns encoded) name, which is an invalid name. Similar with unpacking, we can't unpack 256B (dns encoded) name, because it is too long.

Change-Id: I17cc93a93a17a879a2a789629e56ad39999da9ac
GitHub-Last-Rev: ddf151af6c
GitHub-Pull-Request: golang/net#156
Reviewed-on: https://go-review.googlesource.com/c/net/+/448156
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Mateusz Poliwczak <mpoliwczak34@gmail.com>
2023-05-15 16:52:49 +00:00
Mateusz Poliwczak
ca03788e71 dns/dnsmessage: remove unnecessary []byte conversions
Change-Id: I1a5445584d582e8ace9d336a83e39d3a55d6ab45
GitHub-Last-Rev: 283a809ae9
GitHub-Pull-Request: golang/net#147
Reviewed-on: https://go-review.googlesource.com/c/net/+/426634
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
2022-09-19 22:52:25 +00:00
Mateusz Poliwczak
b0a4917ee2 dns/dnsmessage: use exported MustNewName in example
Change-Id: I517c4cf7c683b26fd80d069cbc2415e5c04339e6
GitHub-Last-Rev: 9437c159f3
GitHub-Pull-Request: golang/net#145
Reviewed-on: https://go-review.googlesource.com/c/net/+/425017
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-22 23:08:55 +00:00
Mateusz Poliwczak
07c6da5e1c dns/dnsmessage: add AD and CD bits support
For golang/go#51152

Change-Id: I1e348afaa1533849e682194efb1c404f9e678e56
GitHub-Last-Rev: c5ef8a56ad
GitHub-Pull-Request: golang/net#136
Reviewed-on: https://go-review.googlesource.com/c/net/+/408654
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-08-09 18:46:13 +00:00
Russ Cox
290c469a71 all: gofmt
Gofmt to update doc comments to the new formatting.

For golang/go#51082.

Change-Id: Iae68a9cd600060577271575e893ecb23bed1e509
Reviewed-on: https://go-review.googlesource.com/c/net/+/399599
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-04-12 02:06:05 +00:00
Brad Fitzpatrick
012df41ee6 dns/dnsmessage: clarify a few things in docs, fix typo
Change-Id: Id01c6552b85cad0554a86bd4aa4547dbea4983eb
Reviewed-on: https://go-review.googlesource.com/c/net/+/369354
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
2021-12-05 04:19:11 +00:00
Dan McArdle
cd0ac97f97 dns/dnsmessage: add RFC3597-inspired UnknownResource type
Currently, dnsmessage is not capable of parsing messages that contain
unknown records. Specifically, unpackResourceType returns an error
stating "invalid resource type".

This makes it tricky to use dnsmessage for applications such as
recursive resolvers or DNS forwarders. (I was bitten already, which is
why I'm writing this!)

RFC3597 indicates that name servers and resolvers must treat unknown RRs
as binary data. Quoting the first paragraph from section 3 below:

>   To enable new RR types to be deployed without server changes, name
>   servers and resolvers MUST handle RRs of unknown type transparently.
>   That is, they must treat the RDATA section of such RRs as
>   unstructured binary data, storing and transmitting it without change
>   [RFC1123].

Fixes #42128

Change-Id: I2a203177e6e6cf51d70c63568c0465fc36a49afe
Reviewed-on: https://go-review.googlesource.com/c/net/+/262037
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Dmitri Shuralyov <dmitshur@golang.org>
2021-03-30 21:00:36 +00:00
Russ Cox
ab34263943 dns/dnsmessage: remove use of fmt that crept in
This package cannot use fmt, because standard package net imports it.
(Most of the package is already clean, including Type.String.)

For golang/go#40070.

Change-Id: I9be92e98d9f5dcfb26852d38004e05f07df5e17a
Reviewed-on: https://go-review.googlesource.com/c/net/+/241085
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2020-07-07 03:43:11 +00:00
Ian Lance Taylor
244492dfa3 dns/dnsmessage: correct error message to be readable
My earlier change CL 220798 avoided a vet warning for string(i),
but neglected to consider that the vet warning was accurate:
the code was wrong.  The code assumed that string(rune(i)) would
return a readable version of i, but of course it instead returns
the UTF-8 encoding of i.

Updates golang/go#32479

Change-Id: I7410bf9fcd98cbdd193344118ecc81e967a6fb45
Reviewed-on: https://go-review.googlesource.com/c/net/+/221437
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-03-01 02:21:30 +00:00
Ian Lance Taylor
491c5fce72 dns/dnsmessage: avoid string(i) where i has type int
Instead use string(r) where r has type rune.

This is in preparation for a vet warning for string(i).

Updates golang/go#32479

Change-Id: I778323fe01eeac4a1068a350c965039eef84df30
Reviewed-on: https://go-review.googlesource.com/c/net/+/220798
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Akhil Indurti <aindurti@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Toshihiro Shiino <shiino.toshihiro@gmail.com>
2020-02-26 05:17:49 +00:00
Tobias Klauser
5d076fcf07 dns/dnsmessage: remove unused funcs skipText and skipBytes
Change-Id: Ie34e3ec7e83ac98181725238e0010ddb941174c7
Reviewed-on: https://go-review.googlesource.com/c/net/+/220457
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
2020-02-25 22:33:29 +00:00
Ainar Garipov
a7b16738d8 all: fix typos
Change-Id: I86005e1f17747e4ffe4fc544546e980b987bad36
Reviewed-on: https://go-review.googlesource.com/c/net/+/193799
Reviewed-by: Toshihiro Shiino <shiino.toshihiro@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-09-09 00:30:24 +00:00
Ian Gudger
8887df42c7 dns/dnsmessage: fix bug in length fixup
If during packing, the byte slice gets re-allocated between packing the
ResourceHeader and ResourceBody, the length will get updated in the old
byte slice before re-allocation resulting in a zero length in the final
packed message.

This change fixes the bug by passing the offset at which the length
should be written instead of a slice of the output byte slice from
ResourceHeader encoding step.

Updates golang/go#16218

Change-Id: Ifd7e2f549b7087ed5b52eaa6ae78970fec4ad988
Reviewed-on: https://go-review.googlesource.com/123835
Run-TryBot: Ian Gudger <igudger@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-07-18 18:21:12 +00:00
Mikio Hara
7d20a46f6b dns/dnsmessage: gofmt -w -s
Change-Id: Iba4cf005f521a1ab7ff721f023222c364056af20
Reviewed-on: https://go-review.googlesource.com/122416
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-07-06 02:06:38 +00:00
Ian Gudger
87b3feba56 dns/dnsmessage: implement fmt.GoStringer.GoString
This improves the debugability of the library and eases the transition
to this library. For example, test DNS messages defined with another DNS
library can be packed and then unpacked with this library. These
unpacked messages can have GoString called on them to generate new test
messages defined with this library.

Updates golang/go#16218

Change-Id: I602586500fd8202892ef04187d3bd8a11039cf27
Reviewed-on: https://go-review.googlesource.com/120697
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-07-02 19:55:25 +00:00
Mikio Hara
b68f30494a dns/dnsmessage: align error messages in test
Change-Id: I008840a981179bb9397735b88155d7476ae76599
Reviewed-on: https://go-review.googlesource.com/101296
Reviewed-by: Ian Gudger <igudger@google.com>
2018-03-30 21:55:11 +00:00
Mikio Hara
d9ff770d14 dns/dnsmessage: add basic support for EDNS(0)
This change introduces OPTResourse type to support DNS messages
containing various extension options as defined in RFC 6891.
Parsing and building OPT pseudo records requires allocations like TXT
records.

Also adds DNSSECAllowed, ExtendedRCode and SetEDNS0 methods to
ResourceHeader for convenience.

Updates golang/go#6464.
Updates golang/go#16218.

Change-Id: Ib72cea277201e4122c6b5effa320084ff351c886
Reviewed-on: https://go-review.googlesource.com/47170
Reviewed-by: Ian Gudger <igudger@google.com>
2018-03-30 21:54:24 +00:00
Ian Gudger
24dd3780ca dns/dnsmessage: reject compressed SRV resource records
Updates golang/go#10622

Change-Id: Iadf0ff0fd223a315130941464040aef5e71f6130
Reviewed-on: https://go-review.googlesource.com/100055
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-03-17 17:54:01 +00:00
Ian Gudger
892bf7b0c6 dns/dnsmessage: correctly handle multiple and >255 byte TXT records
Previously, we only accepted a single string for TXT records and then
chunked it into 255 byte segments. This is wrong. TXT records are a
sequence of strings, each up to 255 bytes.

Updates golang/go#24288

Change-Id: Ib2c085ec127ccecf0c7bda930100b667cabc1f4b
Reviewed-on: https://go-review.googlesource.com/100196
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-03-13 21:53:39 +00:00
Ian Gudger
d25186b37f dns/dnsmessage: fix go vet warning about unkeyed composite literals
Updates golang/go#16218

Change-Id: I078395a8c3967c2ac6a6e86f1528a431346b8ff4
Reviewed-on: https://go-review.googlesource.com/98755
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-03-06 06:01:52 +00:00
Ian Gudger
22ae77b799 dns/dnsmessage: change Builder to append and update documentation
The new appending behavior is required for an efficient DNS client.

(*Builder).Start was intended to append, but didn't. This was a mistake
(all tests and examples assumed that it did).

In addition, message compression when appending has been fixed.

Updates golang/go#16218

Change-Id: I3f42aa6e653e2990fa90368a2803e588ea15b85a
Reviewed-on: https://go-review.googlesource.com/97716
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-03-01 19:09:04 +00:00
Lorenz Bauer
2fb46b16b8 dns/dnsmessage: don't use untrusted data to pre-allocate slices
We mustn't use data from p.header to pre-allocate slices for Message.Question, etc.
Otherwise an attacker can force the allocation of several MiB per parsed message,
which can lead to a DoS via putting pressure on the GC.

Fixes golang/go#23214

Change-Id: I6c99577f625b08331b438533adb6b8167bcd1ec5
Reviewed-on: https://go-review.googlesource.com/85135
Reviewed-by: Ian Gudger <igudger@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-02-02 18:09:47 +00:00
Mikio Hara
434ec0c7fe dns/dnsmessage: update docs for terminology alignment
s/packet/message/g

Change-Id: I2adf809bb4b90e78cf894e4cb6832c117042deb7
Reviewed-on: https://go-review.googlesource.com/65830
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Gudger <igudger@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-01-08 09:04:19 +00:00
Ben Burkert
c73622c772 dns/dnsmessage: add AppendPack method to Message
Add an AppendPack method to Message that appends the message data into a
byte buffer. Reusing a buffer allows for a reduction in allocations.

name          time/op
Pack-8        5.04µs ± 1%
AppendPack-8  4.95µs ± 2%

name          alloc/op
Pack-8        6.22kB ± 0%
AppendPack-8  5.71kB ± 0%

name          allocs/op
Pack-8          21.0 ± 0%
AppendPack-8    20.0 ± 0%

Change-Id: I8bb6b07787cf2ba9ef32e1e60a3003a585ec55be
Reviewed-on: https://go-review.googlesource.com/45274
Reviewed-by: Ian Gudger <igudger@google.com>
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-10-27 10:38:34 +00:00
Ian Gudger
02ac38e252 dns/dnsmessage: improve test coverage of skipping
Updates golang/go#16218

Change-Id: I613cf0a65d40a9823c83e0a547fbd48b2236d16e
Reviewed-on: https://go-review.googlesource.com/49630
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
2017-07-19 08:40:00 +00:00
Mikio Hara
f5bfe5c21e dns/dnsmessage: tweak the error value on nil resource body
Change-Id: I17444d1cc3ce03b6947aaae18d4cecdf9c36193f
Reviewed-on: https://go-review.googlesource.com/47110
Reviewed-by: Ian Gudger <igudger@google.com>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
Run-TryBot: Matt Layher <mdlayher@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-07-04 09:14:19 +00:00
Mikio Hara
8663ed5da4 dns/dnsmessage: don't crash with nil resource body
Change-Id: I51969f70d4fc69829fd5a8bcd8a34b3be15b9db0
Reviewed-on: https://go-review.googlesource.com/46930
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-06-28 08:39:13 +00:00
Mikio Hara
455220fa52 dns/dnsmessage: move example code into example_test.go
Also renames the existing example function to make it visible with
godoc command and godoc.org.

Change-Id: I0e5bef22f2a95930c59c6e79f010ba61651012cd
Reviewed-on: https://go-review.googlesource.com/46791
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: Ian Gudger <igudger@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-06-27 22:21:43 +00:00
Mikio Hara
1274847ddf dns/dnsmessage: fix a typo
Change-Id: I288f01233defe6c673ef9dd5ec79353d3663a9af
Reviewed-on: https://go-review.googlesource.com/46790
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Gudger <igudger@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-06-27 22:21:29 +00:00
Ian Gudger
5f8847ae0d dns/dnsmessage: additional test coverage
Updates golang/go#16218

Change-Id: Ice2821e873807ac4222825f0ca6f47b6a53f90b9
Reviewed-on: https://go-review.googlesource.com/46630
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
2017-06-24 00:04:34 +00:00
Ian Gudger
30f03014b4 dns/dnsmessage: allocation free DNS message parsing and building
Parsing and building can now be done 100% allocation free for most
types. Non-name variable-length fields such as TXT records still
require allocations. Building with compression still causes allocations
due to the use of a map. Both parsing and building will perform
allocations in error paths.

Updates golang/go#16218

Change-Id: I644a7776bd0bf4ad20def521cee44eeadc5e9c06
Reviewed-on: https://go-review.googlesource.com/41145
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-06-23 12:57:23 +00:00