]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
tun: account for null termination on Linux
authorJason A. Donenfeld <Jason@zx2c4.com>
Sat, 5 May 2018 00:47:35 +0000 (02:47 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Sat, 5 May 2018 00:47:35 +0000 (02:47 +0200)
tun_linux.go

index a74a9ccb00c71057d1fe130e8dd6615ad0d012fc..446cc1799ec135e4e4c2768d6d57e5f1ae431dd2 100644 (file)
@@ -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
 }