]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
device: add nil check before convert typed error back
authorWenxuan Zhao <viz@linux.com>
Sat, 18 Apr 2020 14:27:39 +0000 (07:27 -0700)
committerDavid Crawshaw <crawshaw@tailscale.com>
Fri, 1 May 2020 14:49:10 +0000 (00:49 +1000)
Since errors.As(err, target) returns false when err is nil,
which cause status set to 1 when no error occurs for Ipc{Get,Set}Operation.

Signed-off-by: Wenxuan Zhao <viz@linux.com>
device/uapi.go

index 1671faa30d61fbd8e35d236f21425a59660f05bf..1080ca117978f0a6f410d98d15db6d996e2dd65e 100644 (file)
@@ -423,7 +423,7 @@ func (device *Device) IpcHandle(socket net.Conn) {
        switch op {
        case "set=1\n":
                err = device.IpcSetOperation(buffered.Reader)
-               if !errors.As(err, &status) {
+               if err != nil && !errors.As(err, &status) {
                        // should never happen
                        device.log.Error.Println("Invalid UAPI error:", err)
                        status = &IPCError{1}
@@ -431,7 +431,7 @@ func (device *Device) IpcHandle(socket net.Conn) {
 
        case "get=1\n":
                err = device.IpcGetOperation(buffered.Writer)
-               if !errors.As(err, &status) {
+               if err != nil && !errors.As(err, &status) {
                        // should never happen
                        device.log.Error.Println("Invalid UAPI error:", err)
                        status = &IPCError{1}