From 2a2197f7e6d18d5477967b299ed734a7b224536d Mon Sep 17 00:00:00 2001 From: michael Date: Tue, 1 Feb 2022 15:31:18 +0100 Subject: [PATCH] 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 --- src/net/dnsclient_unix.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/net/dnsclient_unix.go b/src/net/dnsclient_unix.go index 21aa91f665..7df536b01f 100644 --- a/src/net/dnsclient_unix.go +++ b/src/net/dnsclient_unix.go @@ -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 {