mirror of
https://github.com/nadoo/glider.git
synced 2026-11-19 07:09:42 +08:00
dns: check bytes length in unmarshal message
This commit is contained in:
1 parent
5467e4bbc1
commit
b27f153426
2 files changed
+9
No files matched your search
@@ -119,6 +119,10 @@ func (m *Message) Marshal() ([]byte, error) {
|
||||
|
||||
// UnmarshalMessage unmarshals []bytes to Message
|
||||
func UnmarshalMessage(b []byte) (*Message, error) {
|
||||
if len(b) <= 2+HeaderLen {
|
||||
return nil, errors.New("UnmarshalMessage: not enough data")
|
||||
}
|
||||
|
||||
m := &Message{unMarshaled: b}
|
||||
err := UnmarshalHeader(b[:HeaderLen], &m.Header)
|
||||
if err != nil {
|
||||
@@ -280,6 +284,10 @@ func (m *Message) UnmarshalQuestion(b []byte, q *Question) (n int, err error) {
|
||||
return 0, errors.New("unmarshal question must not be nil")
|
||||
}
|
||||
|
||||
if len(b) <= 5 {
|
||||
return 0, errors.New("UnmarshalQuestion: not enough data")
|
||||
}
|
||||
|
||||
domain, idx, err := m.UnmarshalDomain(b)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
||||
Reference in new issue
Block a user