diff options
| author | Shulhan <ms@kilabit.info> | 2025-01-17 00:09:21 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2025-01-17 00:09:21 +0700 |
| commit | 20101c63d8cb9d5d673bbd2b93f9dfd8344f06a2 (patch) | |
| tree | 1f644467eec6b9085a873a4299ea01c85610076d /lib/dns/message.go | |
| parent | 01c317a295ba743c17064e4656fac22d993c1174 (diff) | |
| download | pakakeh.go-20101c63d8cb9d5d673bbd2b93f9dfd8344f06a2.tar.xz | |
lib/dns: detect invalid header earlier
Previously, we unpack the header and then question without
detecting whether the header itself is valid or not, for
example the op-code, the response code.
This cause the unpacking question return an error like
label length overflow at index xxx
One of the case is when someone sent random or HTTP request
to DoT port.
Diffstat (limited to 'lib/dns/message.go')
| -rw-r--r-- | lib/dns/message.go | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/dns/message.go b/lib/dns/message.go index 02a237c0..058a159e 100644 --- a/lib/dns/message.go +++ b/lib/dns/message.go @@ -5,7 +5,6 @@ package dns import ( - "errors" "fmt" "net" "strconv" @@ -1072,15 +1071,16 @@ func (msg *Message) String() string { // packet. This method assume that message.packet already set to DNS raw // message. func (msg *Message) UnpackHeaderQuestion() (err error) { - if len(msg.packet) <= sectionHeaderSize { - return errors.New(`UnpackHeaderQuestion: missing question`) - } + var logp = `UnpackHeaderQuestion` - msg.Header.unpack(msg.packet) + err = msg.Header.unpack(msg.packet) + if err != nil { + return fmt.Errorf(`%s: %w`, logp, err) + } err = msg.Question.unpack(msg.packet[sectionHeaderSize:]) if err != nil { - return err + return fmt.Errorf(`%s: %w`, logp, err) } return nil |
