From 4febbdbfe5bd80393be8d22a04fef737adc7b784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Serv=C3=A9n=20Mar=C3=ADn?= Date: Fri, 27 Sep 2019 11:10:15 +0200 Subject: [PATCH] pkg/iptables: fix out of bounds err This fixes two bugs in the iptables package that can cause out of bounds errors. Fixes: #22 Thanks to @SerialVelocity for reporting. --- pkg/iptables/iptables.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/iptables/iptables.go b/pkg/iptables/iptables.go index 4c34790..aec9808 100644 --- a/pkg/iptables/iptables.go +++ b/pkg/iptables/iptables.go @@ -206,7 +206,7 @@ func resetFromIndex(i int, rules []Rule) error { if i >= len(rules) { return nil } - for j := range rules[i:] { + for j := i; j < len(rules); j++ { if err := rules[j].Delete(); err != nil { return fmt.Errorf("failed to delete rule: %v", err) } @@ -222,7 +222,7 @@ func deleteFromIndex(i int, rules *[]Rule) error { if i >= len(*rules) { return nil } - for j := range (*rules)[i:] { + for j := i; j < len(*rules); j++ { if err := (*rules)[j].Delete(); err != nil { return fmt.Errorf("failed to delete rule: %v", err) }