From 130775cd16d74401a2206218e2dc0f32d1c59898 Mon Sep 17 00:00:00 2001 From: michael Date: Tue, 1 Feb 2022 14:41:20 +0000 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 Change-Id: I3f0785f71def6649d6089d0af71c9e50f5ccb259 GitHub-Last-Rev: 2a2197f7e6d18d5477967b299ed734a7b224536d GitHub-Pull-Request: golang/go#50948 Reviewed-on: https://go-review.googlesource.com/c/go/+/381966 Reviewed-by: Bryan Mills Reviewed-by: Damien Neil Run-TryBot: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Reviewed-by: Ian Lance Taylor TryBot-Result: Gopher Robot --- 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 15dbc258302..17435365907 100644 --- a/src/net/dnsclient_unix.go +++ b/src/net/dnsclient_unix.go @@ -74,11 +74,14 @@ func newRequest(q dnsmessage.Question) (id uint16, udpReq, tcpReq []byte, err er } 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 {