aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2018-05-05 02:47:59 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2018-05-05 02:47:59 +0200
commit4d9f3a2f535b8ddefff5ed70c8d191106c3030fa (patch)
tree8ab88417196ff060a23c4f023f646d820855bee7
parentMerge branch 'master' of ssh://git.zx2c4.com/wireguard-go (diff)
parenttun: account for null termination on Linux (diff)
downloadwireguard-go-4d9f3a2f535b8ddefff5ed70c8d191106c3030fa.tar.xz
wireguard-go-4d9f3a2f535b8ddefff5ed70c8d191106c3030fa.zip
Merge branch 'master' of ssh://git.zx2c4.com/wireguard-go
Diffstat (limited to '')
-rw-r--r--tun_linux.go8
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
}