From df23697ae7876703db8912812377377c99953151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Luk=C5=A1a?= Date: Tue, 28 May 2019 11:38:27 +0200 Subject: [PATCH] Better error message if panic occurs during iptables-save output parsing --- pkg/util/iptables/save_restore.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/util/iptables/save_restore.go b/pkg/util/iptables/save_restore.go index 172f07e7fa5..7ec11e4f00f 100644 --- a/pkg/util/iptables/save_restore.go +++ b/pkg/util/iptables/save_restore.go @@ -61,7 +61,11 @@ func GetChainLines(table Table, save []byte) map[Chain][]byte { } else if line[0] == ':' && len(line) > 1 { // We assume that the contains space - chain lines have 3 fields, // space delimited. If there is no space, this line will panic. - chain := Chain(line[1:bytes.Index(line, spaceBytes)]) + spaceIndex := bytes.Index(line, spaceBytes) + if spaceIndex == -1 { + panic(fmt.Sprintf("Unexpected chain line in iptables-save output: %v", string(line))) + } + chain := Chain(line[1:spaceIndex]) chainsMap[chain] = line } }