gravitl / netmaker

Netmaker makes networks with WireGuard. Netmaker automates fast, secure, and distributed virtual networks.
https://netmaker.io
Other
9.4k stars 547 forks source link

[Bug]: netclient segfault when leaving network #1513

Closed dylancarruthers closed 2 years ago

dylancarruthers commented 2 years ago

Contact Details

dylan.carruthers@reivernet.com

What happened?

I used the netclient to get a node to leave a network (using sudo) and received a segfault.

$ sudo netclient leave --network mynetwork

The node was was removed from the network in the Netmaker dashboard despite the error.

I ran the same command again and got the correct error (you're not allowed on here) and the same segfault

The configuration files in /etc/netclient/config have not been deleted and had to be removed manually.

Version

v0.15.0

What OS are you using?

Linux

Relevant log output

dylan at mynode in ~ 
$ sudo netclient leave --network mynetwork
[netclient] 2022-09-02 21:57:16 network: mynetwork deleted node mynode . 
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x79c0f0]

goroutine 1 [running]:
github.com/gravitl/netmaker/netclient/local.FlushPeerRoutes({0xc0000f2d60, 0xc}, {0xc0000f29b0, 0xa}, {0xc000128780, 0x4, 0xc000092840?})
        /home/runner/work/netmaker/netmaker/netclient/local/routes.go:109 +0x1f0
github.com/gravitl/netmaker/netclient/functions.LeaveNetwork({0x7ffc7db1d8bc?, 0x9bf536?})
        /home/runner/work/netmaker/netmaker/netclient/functions/common.go:209 +0x745
github.com/gravitl/netmaker/netclient/command.Leave(0xc0004b8dc8)
        /home/runner/work/netmaker/netmaker/netclient/command/commands.go:53 +0x33
github.com/gravitl/netmaker/netclient/cli_options.GetCommands.func2(0xc00009e480?)
        /home/runner/work/netmaker/netmaker/netclient/cli_options/cmds.go:39 +0xdd
github.com/urfave/cli/v2.(*Command).Run(0xc00009e480, 0xc00039cec0)
        /home/runner/go/pkg/mod/github.com/urfave/cli/v2@v2.11.2/command.go:173 +0x6a2
github.com/urfave/cli/v2.(*App).RunContext(0xc0000b8380, {0xaac010?, 0xc0000260e8}, {0xc00001e080, 0x4, 0x4})
        /home/runner/go/pkg/mod/github.com/urfave/cli/v2@v2.11.2/app.go:382 +0xfb5
github.com/urfave/cli/v2.(*App).Run(...)
        /home/runner/go/pkg/mod/github.com/urfave/cli/v2@v2.11.2/app.go:251
main.main()
        /home/runner/work/netmaker/netmaker/netclient/main.go:48 +0x23b

dylan at mynode in ~ 
$ sudo netclient leave --network mynetwork
[netclient] 2022-09-02 21:57:26 network: mynetwork unable to authenticate: failed to authenticate 400 Bad Request {"Code":400,"Message":"no result found"} 
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x79c0f0]

goroutine 1 [running]:
github.com/gravitl/netmaker/netclient/local.FlushPeerRoutes({0xc0000f2da0, 0xc}, {0xc0000f29f0, 0xa}, {0xc000128000, 0x4, 0xff0000c0004be048?})
        /home/runner/work/netmaker/netmaker/netclient/local/routes.go:109 +0x1f0
github.com/gravitl/netmaker/netclient/functions.LeaveNetwork({0x7ffe85a868bc?, 0x9bf536?})
        /home/runner/work/netmaker/netmaker/netclient/functions/common.go:209 +0x745
github.com/gravitl/netmaker/netclient/command.Leave(0xc0004e6dc8)
        /home/runner/work/netmaker/netmaker/netclient/command/commands.go:53 +0x33
github.com/gravitl/netmaker/netclient/cli_options.GetCommands.func2(0xc000354360?)
        /home/runner/work/netmaker/netmaker/netclient/cli_options/cmds.go:39 +0xdd
github.com/urfave/cli/v2.(*Command).Run(0xc000354360, 0xc0003a0fc0)
        /home/runner/go/pkg/mod/github.com/urfave/cli/v2@v2.11.2/command.go:173 +0x6a2
github.com/urfave/cli/v2.(*App).RunContext(0xc0000b6380, {0xaac010?, 0xc0000260e8}, {0xc00001e080, 0x4, 0x4})
        /home/runner/go/pkg/mod/github.com/urfave/cli/v2@v2.11.2/app.go:382 +0xfb5
github.com/urfave/cli/v2.(*App).Run(...)
        /home/runner/go/pkg/mod/github.com/urfave/cli/v2@v2.11.2/app.go:251
main.main()
        /home/runner/work/netmaker/netmaker/netclient/main.go:48 +0x23b

Contributing guidelines

dylancarruthers commented 2 years ago

Ubuntu 22.04.1 LTS Linux mynode 5.15.0-47-generic #51-Ubuntu SMP Thu Aug 11 07:51:15 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

afeiszli commented 2 years ago

There's a fix for this in develop, will be resolved in 0.15.1

https://github.com/gravitl/netmaker/blob/develop/netclient/local/routes.go#L109

afeiszli commented 2 years ago

Closing, since fix is in 0.15.1