]> Cypherpunks repositories - gostls13.git/commitdiff
net: improve error handling in dnsclient_unix.go
authormichael <info@komika.org>
Tue, 1 Feb 2022 14:41:20 +0000 (14:41 +0000)
committerGopher Robot <gobot@golang.org>
Sat, 7 May 2022 00:24:17 +0000 (00:24 +0000)
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 <bcmills@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/net/dnsclient_unix.go

index 15dbc258302763f12c0965e4392f69723ef50064..17435365907ad5d81b275985993d557b5c712668 100644 (file)
@@ -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 {