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_test.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_test.go')
| -rw-r--r-- | lib/dns/message_test.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/dns/message_test.go b/lib/dns/message_test.go index 8a1d47b2..a2f07b8b 100644 --- a/lib/dns/message_test.go +++ b/lib/dns/message_test.go @@ -1210,6 +1210,42 @@ func TestMessageSetResponseCode(t *testing.T) { } } +func TestMessage_UnpackHeaderQuestion(t *testing.T) { + var tdata *test.Data + var err error + tdata, err = test.LoadData(`testdata/message/UnpackHeaderQuestion_test.txt`) + if err != nil { + t.Fatal(err) + } + + var name string + var rawb []byte + var msg Message + for name, rawb = range tdata.Input { + t.Run(name, func(t *testing.T) { + msg.packet, err = hexdump.Parse(rawb, true) + if err != nil { + t.Fatal(err) + } + + err = msg.UnpackHeaderQuestion() + if err != nil { + var expError = tdata.Output[name+`Error`] + test.Assert(t, `error`, string(expError), + err.Error()) + return + } + + rawb, err = json.MarshalIndent(&msg, ``, ` `) + if err != nil { + t.Fatal(err) + } + test.Assert(t, `message`, string(tdata.Output[name]), + string(rawb)) + }) + } +} + func TestUnpackMessage(t *testing.T) { type testCase struct { exp *Message |
