Skip to content

Commit

Permalink
Fixes panic with cleaning blank IPs (#676)
Browse files Browse the repository at this point in the history
  • Loading branch information
hhhjort authored and dbemiller committed Sep 12, 2018
1 parent b7f4f12 commit 0b49720
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions exchange/gdpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,18 @@ func cleanPI(bidRequest *openrtb.BidRequest) {
// Zero the last byte of an IP address
func cleanIP(fullIP string) string {
i := strings.LastIndex(fullIP, ".")
if i == -1 {
return ""
}
return fullIP[0:i] + ".000"
}

// Zero the last two bytes of an IPv6 address
func cleanIPv6(fullIP string) string {
i := strings.LastIndex(fullIP, ":")
if i == -1 {
return ""
}
return fullIP[0:i] + ":0000"
}

Expand Down
8 changes: 8 additions & 0 deletions exchange/gdpr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,11 @@ func assertStringEmpty(t *testing.T, str string) {
t.Errorf("Expected an empty string, got %s", str)
}
}

func TestBadIPs(t *testing.T) {
assertStringEmpty(t, cleanIP("not an IP"))
assertStringEmpty(t, cleanIP(""))
assertStringEmpty(t, cleanIP("36278042"))
assertStringEmpty(t, cleanIPv6("not an IP"))
assertStringEmpty(t, cleanIPv6(""))
}

0 comments on commit 0b49720

Please sign in to comment.