diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-05 02:47:35 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-05 02:47:35 +0200 |
commit | 4a177de09c067ffb94c05f0859d10f78961bd3b4 (patch) | |
tree | a20761d6af2ef62a2b54102e791c7787e8d9c556 /tun_linux.go | |
parent | e1de0f229a8f2cbfc4bb56230de885386a775fd6 (diff) |
tun: account for null termination on Linux
Diffstat (limited to 'tun_linux.go')
-rw-r--r-- | tun_linux.go | 8 |
1 files changed, 7 insertions, 1 deletions
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 } |