Merge pull request #7738 from Xuanqing-Shi/7732/handle-non-empty-endpoints-in-RemoveEndpoints

runtime: incorrect handling of non-empty []Endpoint parameter in Remo…
This commit is contained in:
Peng Tao 2023-09-18 10:58:28 +08:00 committed by GitHub
commit 6eedd9b0b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -229,12 +229,17 @@ func (n *LinuxNetwork) addSingleEndpoint(ctx context.Context, s *Sandbox, netInf
return endpoint, nil
}
func (n *LinuxNetwork) removeSingleEndpoint(ctx context.Context, s *Sandbox, idx int, hotplug bool) error {
if idx > len(n.eps)-1 {
return fmt.Errorf("Endpoint index overflow")
func (n *LinuxNetwork) removeSingleEndpoint(ctx context.Context, s *Sandbox, endpoint Endpoint, hotplug bool) error {
var idx int = len(n.eps)
for i, val := range n.eps {
if val.HardwareAddr() == endpoint.HardwareAddr() {
idx = i
break
}
}
if idx == len(n.eps) {
return fmt.Errorf("Endpoint not found")
}
endpoint := n.eps[idx]
if endpoint.GetRxRateLimiter() {
networkLogger().WithField("endpoint-type", endpoint.Type()).Info("Deleting rx rate limiter")
@ -402,7 +407,7 @@ func (n *LinuxNetwork) RemoveEndpoints(ctx context.Context, s *Sandbox, endpoint
eps = endpoints
}
for idx, ep := range eps {
for _, ep := range eps {
if endpoints != nil {
new_ep, _ := findEndpoint(ep, n.eps)
if new_ep == nil {
@ -410,7 +415,7 @@ func (n *LinuxNetwork) RemoveEndpoints(ctx context.Context, s *Sandbox, endpoint
}
}
if err := n.removeSingleEndpoint(ctx, s, idx, hotplug); err != nil {
if err := n.removeSingleEndpoint(ctx, s, ep, hotplug); err != nil {
return err
}
}