Skip to content

Commit

Permalink
Fix: Panic (from IP.Parse())
Browse files Browse the repository at this point in the history
If the IP address is neither v4 or v6, IP.Parse() returns "nil".

Related: #64
  • Loading branch information
till committed Apr 8, 2021
1 parent 4626733 commit 17992a5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
10 changes: 9 additions & 1 deletion collector/rbl.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,15 @@ func (rbl *Rbl) lookup(rblList string, targetHost string) []Rblresult {
res.Address = ip
res.Rbl = rblList

revIP := godnsbl.Reverse(net.ParseIP(ip))
// attempt to "validate" the IP
ValidIPAddress := net.ParseIP(ip)
if ValidIPAddress == nil {
log.Errorf("Unable to parse IP: %s", ip)
continue
}

// reverse it, for the look up
revIP := godnsbl.Reverse(ValidIPAddress)

rbl.query(revIP, rblList, &res)

Expand Down
20 changes: 20 additions & 0 deletions collector/rbl_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package collector

import (
"os"
"testing"

log "github.com/sirupsen/logrus"
)

func TestUpdate(t *testing.T) {
log.SetLevel(log.DebugLevel)
log.SetOutput(os.Stdout)

rbl := NewRbl("0.0.0.0:53")
rbl.Update("this.is.not.an.ip", []string{"cbl.abuseat.org"})

if len(rbl.Results) > 0 {
t.Errorf("Got a result, but shouldn't have: %v", rbl.Results)
}
}

0 comments on commit 17992a5

Please sign in to comment.