hashicorp / hashicorp/consul

Starting consul with some ports disabled will cause invalid memory address or nil pointer dereference

Open
#16,715 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Go
Stars
30.1k
Forks
4.6k
Avg merge
1d 18h
Merged PRs (30d)
39

Description

#### Overview of the Issue

Starting `consul` with some ports set to `0` causes it to crash. To be clear, I know that disabling these ports doesn't really make much sense when running Consul but it really shouldn't be a memory violation. This needs to be handled gracefully.

---

#### Reproduction Steps

1. `consul agent -dev -serf-lan-port 0`
1. `consul agent -dev -server-port 0`

### Consul info for both Client and Server

```
consul version
Consul v1.15.1
Build Date 1970-01-01T00:00:01Z
Protocol 2 spoken by default, understands 2 to 3 (agent will automatically use protocol >2 when speaking to compatible agents)
```
### Operating system and Environment details

Arch Linux

### Log Fragments

```
consul agent -dev -server-port 0
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x2a84565]

goroutine 1 [running]:
github.com/hashicorp/consul/agent.newConnPool(0xc000611000, {0x41f4060, 0xc001167cb0}, 0xc000739e00)
github.com/hashicorp/consul/agent/setup.go:199 +0x65
github.com/hashicorp/consul/agent.NewBaseDeps(0xc00047e1a0, {0x41a8b60, 0xc000075d10}, {_, _})
github.com/hashicorp/consul/agent/setup.go:116 +0x8f8
github.com/hashicorp/consul/command/agent.(*cmd).run(0xc000f87000, {0xc0000740c0, 0x3, 0x3})
github.com/hashicorp/consul/command/agent/agent.go:168 +0x4f7
github.com/hashicorp/consul/command/agent.(*cmd).Run(0xc000f87000, {0xc0000740c0?, 0xffffffffffffffff?, 0x0?})
github.com/hashicorp/consul/command/agent/agent.go:70 +0x27
github.com/mitchellh/cli.(*CLI).Run(0xc00090cb40)
github.com/mitchellh/cli@v1.1.0/cli.go:260 +0x5f8
main.realMain()
github.com/hashicorp/consul/main.go:48 +0x40f
main.main()
github.com/hashicorp/consul/main.go:18 +0x19
```

Contributor guide

Open the contributing guide

Research direction

Start with agent/setup.go, especially newConnPool and NewBaseDeps, then reproduce the crash with consul agent -dev -server-port 0 and -serf-lan-port 0. Done means Consul handles disabled ports gracefully without a nil pointer dereference or panic.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
distributed-systems, networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.