From aa391ce525327fde71bc3b8008f4b2e18f9c02b4 Mon Sep 17 00:00:00 2001 From: ScriptTiger Date: Wed, 11 Sep 2024 09:08:56 +0800 Subject: [PATCH] Improved input validation --- hosts-bl.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hosts-bl.go b/hosts-bl.go index ef8a027..267f702 100644 --- a/hosts-bl.go +++ b/hosts-bl.go @@ -318,8 +318,10 @@ func deDupe(hbits int) { // Function to scrub input func scrubInput(line string, fbhPtr *string, cmts bool) ([]string) { - if strings.ContainsAny(line, " .") && strings.HasPrefix(line, *fbhPtr) { - line = strings.SplitAfterN(line, " ", 2)[1] + if strings.Contains(line, " ") && strings.Contains(line, ".") && strings.HasPrefix(line, *fbhPtr) { + lineSegments := strings.SplitAfterN(line, " ", 2) + if len(lineSegments) != 2 {return nil} + line = lineSegments[1] if strings.ContainsAny(line, "#") {line = strings.TrimSuffix(strings.SplitAfterN(line, "#", 2)[0], "#")} line = strings.TrimSpace(line) if line == "0.0.0.0" {return nil}