From: Jason A. Donenfeld Date: Sat, 5 May 2018 00:47:35 +0000 (+0200) Subject: tun: account for null termination on Linux X-Git-Tag: 0.0.20180514~44^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4a177de09c067ffb94c05f0859d10f78961bd3b4;p=thirdparty%2Fwireguard-go.git tun: account for null termination on Linux --- diff --git a/tun_linux.go b/tun_linux.go index a74a9cc..446cc17 100644 --- a/tun_linux.go +++ b/tun_linux.go @@ -19,6 +19,7 @@ import ( "net" "os" "strconv" + "bytes" "strings" "syscall" "time" @@ -268,7 +269,12 @@ func (tun *NativeTun) Name() (string, error) { if errno != 0 { return "", errors.New("Failed to get name of TUN device: " + strconv.FormatInt(int64(errno), 10)) } - tun.name = string(ifr[:]) + nullStr := ifr[:] + i := bytes.IndexByte(nullStr, 0) + if i != -1 { + nullStr = nullStr[:i] + } + tun.name = string(nullStr) return tun.name, nil }