5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-21 18:20:29 +00:00

Check tun.config is not equal to nil before usage (#830)

We have to check tun.config is not nil before first use, not after.
This commit is contained in:
Fyodor Ustinov 2021-09-21 23:19:25 +03:00 committed by GitHub
parent 3613614b41
commit 52345a2de4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -114,11 +114,11 @@ func (tun *TunAdapter) _start() error {
if tun.isOpen {
return errors.New("TUN module is already started")
}
tun.config.RLock()
defer tun.config.RUnlock()
if tun.config == nil {
return errors.New("no configuration available to TUN")
}
tun.config.RLock()
defer tun.config.RUnlock()
tun.addr = tun.rwc.Address()
tun.subnet = tun.rwc.Subnet()
addr := fmt.Sprintf("%s/%d", net.IP(tun.addr[:]).String(), 8*len(address.GetPrefix())-1)