Browse Source

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.
Lucas Servén Marín 6 years ago
parent
commit
4febbdbfe5
1 changed files with 2 additions and 2 deletions
  1. 2 2
      pkg/iptables/iptables.go

+ 2 - 2
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)
 		}