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.
This commit is contained in:
Lucas Servén Marín 2019-09-27 11:10:15 +02:00
parent 3facc9f34f
commit 4febbdbfe5
No known key found for this signature in database
GPG Key ID: 586FEAF680DA74AD

View File

@ -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)
}