Skip to content

Controller: fix panic in convergeBalancer#1168

Merged
fedepaol merged 1 commit intometallb:mainfrom
oribon:fix_controller_panic
Jan 17, 2022
Merged

Controller: fix panic in convergeBalancer#1168
fedepaol merged 1 commit intometallb:mainfrom
oribon:fix_controller_panic

Conversation

@oribon
Copy link
Member

@oribon oribon commented Jan 16, 2022

The controller can panic if a user updated a service by specifying
a different IP than the one currently assigned and changing another
field that causes the controller to clear the service's state.

For example, updating the address pool of a service and specifying
spec.loadBalancerIP from the new address pool results in:

panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
main.(*controller).convergeBalancer(0xc0001205a0, {0x15cf500, 0xc0001bbc20}, {0xc0002b8730, 0xf}, 0xc000132c80)
        /home/obraunsh/projects/metallb/controller/service.go:118 +0x2306

Signed-off-by: Ori Braunshtein obraunsh@redhat.com

The controller can panic if a user updated a service by specifying
a different IP than the one currently assigned and changing another
field that causes the controller to clear the service's state.

For example, updating the address pool of a service and specifying
spec.loadBalancerIP from the new address pool results in:
```
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
main.(*controller).convergeBalancer(0xc0001205a0, {0x15cf500, 0xc0001bbc20}, {0xc0002b8730, 0xf}, 0xc000132c80)
        /home/obraunsh/projects/metallb/controller/service.go:119 +0x2306
```

Signed-off-by: Ori Braunshtein <obraunsh@redhat.com>
return true
}
if svc.Spec.LoadBalancerIP != lbIPs[0].String() {
if len(lbIPs) != 0 && svc.Spec.LoadBalancerIP != lbIPs[0].String() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be on the paranoid side and clear also if len(lbIPs) == 0 && svc.Spec.LoadBalancerIP != ""

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

len(lbIPs) == 0 at this point could only happen if the state was already cleared, should I still add it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either in that scenario, or if the service comes in without ips assigned. Again, I would say that it's not necessary, but I prefer being on the paranoid side.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, I just noticed we are inside a if len(lbIPs) != 0 {

@fedepaol
Copy link
Member

LGTM

@fedepaol fedepaol merged commit a3b0d5f into metallb:main Jan 17, 2022
fedepaol pushed a commit to fedepaol/metallb that referenced this pull request Jan 24, 2022
The controller can panic if a user updated a service by specifying
a different IP than the one currently assigned and changing another
field that causes the controller to clear the service's state.

For example, updating the address pool of a service and specifying
spec.loadBalancerIP from the new address pool results in:
```
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
main.(*controller).convergeBalancer(0xc0001205a0, {0x15cf500, 0xc0001bbc20}, {0xc0002b8730, 0xf}, 0xc000132c80)
        /home/obraunsh/projects/metallb/controller/service.go:119 +0x2306
```

Signed-off-by: Ori Braunshtein <obraunsh@redhat.com>
fedepaol pushed a commit to fedepaol/metallb that referenced this pull request Jan 25, 2022
The controller can panic if a user updated a service by specifying
a different IP than the one currently assigned and changing another
field that causes the controller to clear the service's state.

For example, updating the address pool of a service and specifying
spec.loadBalancerIP from the new address pool results in:
```
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
main.(*controller).convergeBalancer(0xc0001205a0, {0x15cf500, 0xc0001bbc20}, {0xc0002b8730, 0xf}, 0xc000132c80)
        /home/obraunsh/projects/metallb/controller/service.go:119 +0x2306
```

Signed-off-by: Ori Braunshtein <obraunsh@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants