Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotate unpack* function errors with where the error happened. #1590

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ func (dns *Msg) unpack(dh Header, msg []byte, off int) (err error) {
// TODO(miek) make this an error?
// use PackOpt to let people tell how detailed the error reporting should be?
// if off != len(msg) {
// // println("dns: extra bytes in dns packet", off, "<", len(msg))
// // println("dns: extra bytes in dns packet", off, "<", len(msg))
// }
return err

Expand Down Expand Up @@ -1123,23 +1123,28 @@ func unpackQuestion(msg []byte, off int) (Question, int, error) {
)
q.Name, off, err = UnpackDomainName(msg, off)
if err != nil {
return q, off, err
return q, off, fmt.Errorf("question.Name: %w", err)
}
if off == len(msg) {
return q, off, nil
}
q.Qtype, off, err = unpackUint16(msg, off)
if err != nil {
return q, off, err
return q, off, fmt.Errorf("question.Qtype: %w", err)
}
if off == len(msg) {
return q, off, nil
}
q.Qclass, off, err = unpackUint16(msg, off)
if err != nil {
return q, off, fmt.Errorf("question.Qclass: %w", err)
}

if off == len(msg) {
return q, off, nil
}
return q, off, err

return q, off, nil
}

func (dh *Header) pack(msg []byte, off int, compression compressionMap, compress bool) (int, error) {
Expand Down Expand Up @@ -1177,27 +1182,27 @@ func unpackMsgHdr(msg []byte, off int) (Header, int, error) {
)
dh.Id, off, err = unpackUint16(msg, off)
if err != nil {
return dh, off, err
return dh, off, fmt.Errorf("header.Id: %w", err)
}
dh.Bits, off, err = unpackUint16(msg, off)
if err != nil {
return dh, off, err
return dh, off, fmt.Errorf("header.Bits: %w", err)
}
dh.Qdcount, off, err = unpackUint16(msg, off)
if err != nil {
return dh, off, err
return dh, off, fmt.Errorf("header.Qdcount: %w", err)
}
dh.Ancount, off, err = unpackUint16(msg, off)
if err != nil {
return dh, off, err
return dh, off, fmt.Errorf("header.Ancount: %w", err)
}
dh.Nscount, off, err = unpackUint16(msg, off)
if err != nil {
return dh, off, err
return dh, off, fmt.Errorf("header.Nscount: %w", err)
}
dh.Arcount, off, err = unpackUint16(msg, off)
if err != nil {
return dh, off, err
return dh, off, fmt.Errorf("header.Arcount: %w", err)
}
return dh, off, nil
}
Expand Down
12 changes: 9 additions & 3 deletions msg_generate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading