From: Wenxuan Zhao Date: Sat, 18 Apr 2020 14:27:39 +0000 (-0700) Subject: device: add nil check before convert typed error back X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=75a41b24ad2937169a6b4d0a2909dac1ffff726f;p=thirdparty%2Fwireguard-go.git device: add nil check before convert typed error back 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 --- diff --git a/device/uapi.go b/device/uapi.go index 1671faa..1080ca1 100644 --- a/device/uapi.go +++ b/device/uapi.go @@ -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}