-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
- Loading branch information
Showing
2 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,6 +91,7 @@ var ( | |
errTooManyAdditionals = errors.New("too many Additionals to pack (>65535)") | ||
errNonCanonicalName = errors.New("name is not in canonical format (it must end with a .)") | ||
errStringTooLong = errors.New("character string exceeds maximum length (255)") | ||
errCompressedSRV = errors.New("compressed name in SRV resource data") | ||
) | ||
|
||
// Internal constants. | ||
|
@@ -1610,6 +1611,10 @@ func (n *Name) pack(msg []byte, compression map[string]int, compressionOff int) | |
|
||
// unpack unpacks a domain name. | ||
func (n *Name) unpack(msg []byte, off int) (int, error) { | ||
return n.unpackCompressed(msg, off, true /* allowCompression */) | ||
} | ||
|
||
func (n *Name) unpackCompressed(msg []byte, off int, allowCompression bool) (int, error) { | ||
// currOff is the current working offset. | ||
currOff := off | ||
|
||
|
@@ -1645,6 +1650,9 @@ Loop: | |
name = append(name, '.') | ||
currOff = endOff | ||
case 0xC0: // Pointer | ||
if !allowCompression { | ||
return off, errCompressedSRV | ||
} | ||
if currOff >= len(msg) { | ||
return off, errInvalidPtr | ||
} | ||
|
@@ -2044,7 +2052,7 @@ func unpackSRVResource(msg []byte, off int) (SRVResource, error) { | |
return SRVResource{}, &nestedError{"Port", err} | ||
} | ||
var target Name | ||
if _, err := target.unpack(msg, off); err != nil { | ||
if _, err := target.unpackCompressed(msg, off, false /* allowCompression */); err != nil { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ianlancetaylor
Member
|
||
return SRVResource{}, &nestedError{"Target", err} | ||
} | ||
return SRVResource{priority, weight, port, target}, nil | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
isn't this against the robustness principle ? Be tolerant in what you accept !