client.go | 4 +++- iplist/iplist.go | 12 +++++++++++- diff --git a/client.go b/client.go index 9a427faf68e9f5bff6974dae9e71c81d068dbe46..eddfcff8133b64655fcadb16dc1fa411ffe27f3a 100644 --- a/client.go +++ b/client.go @@ -380,12 +380,14 @@ defer f.Close() var ranges []iplist.Range uniqStrs := make(map[string]string) scanner := bufio.NewScanner(f) + lineNum := 1 for scanner.Scan() { r, ok, lineErr := iplist.ParseBlocklistP2PLine(scanner.Bytes()) if lineErr != nil { - err = fmt.Errorf("error reading torrent blocklist line: %s", lineErr) + err = fmt.Errorf("error reading torrent blocklist line %d: %s", lineNum, lineErr) return } + lineNum++ if !ok { continue } diff --git a/iplist/iplist.go b/iplist/iplist.go index 756c0263d5d62fe8fe1d0aeb7672814f3441c199..2145b297fc5a1dc9fafabe3d8527fbd9628d40c3 100644 --- a/iplist/iplist.go +++ b/iplist/iplist.go @@ -2,6 +2,7 @@ package iplist import ( "bytes" + "errors" "fmt" "net" "sort" @@ -67,7 +68,16 @@ if len(l) == 0 || bytes.HasPrefix(l, []byte("#")) { return } colon := bytes.IndexByte(l, ':') - hyphen := bytes.IndexByte(l[colon+1:], '-') + colon + 1 + if colon == -1 { + err = errors.New("missing colon") + return + } + hyphen := bytes.IndexByte(l[colon+1:], '-') + if hyphen == -1 { + err = errors.New("missing hyphen") + return + } + hyphen += colon + 1 r.Description = string(l[:colon]) r.First = net.ParseIP(string(l[colon+1 : hyphen])) r.Last = net.ParseIP(string(l[hyphen+1:]))