1
0
mirror of https://github.com/golang/go synced 2024-11-17 12:14:47 -07:00

net: improve error handling in dnsclient_unix.go

In the file net/dnsclient_unix.go in the function newRequest
error handling is missing after calling b.Finish(). If
the implementation of dnsmessage.Builder.Finish changes
it is theoretically possible that the missing error handling
introduces a nil pointer exception.

Fixes #50946
This commit is contained in:
michael 2022-02-01 15:31:18 +01:00
parent 4fea5935f5
commit 2a2197f7e6
No known key found for this signature in database
GPG Key ID: FACE18D82DD1F5CC

View File

@ -57,11 +57,14 @@ func newRequest(q dnsmessage.Question) (id uint16, udpReq, tcpReq []byte, err er
return 0, nil, nil, err
}
tcpReq, err = b.Finish()
if err != nil {
return 0, nil, nil, err
}
udpReq = tcpReq[2:]
l := len(tcpReq) - 2
tcpReq[0] = byte(l >> 8)
tcpReq[1] = byte(l)
return id, udpReq, tcpReq, err
return id, udpReq, tcpReq, nil
}
func checkResponse(reqID uint16, reqQues dnsmessage.Question, respHdr dnsmessage.Header, respQues dnsmessage.Question) bool {