diff --git a/backend/api_v1/rdns.go b/backend/api_v1/rdns.go index ff74b18..5c69ed4 100644 --- a/backend/api_v1/rdns.go +++ b/backend/api_v1/rdns.go @@ -16,8 +16,6 @@ type rdnsParams struct { func rdns(g group, log *zap.Logger, dnsServer string) { g.GET("/:ip", func(ctx *gin.Context) { - ip := ctx.Param("ip") - isJson := ctx.ContentType() == "application/json" var params rdnsParams if err := ctx.BindQuery(¶ms); err != nil { @@ -31,6 +29,19 @@ func rdns(g group, log *zap.Logger, dnsServer string) { return } + ip := ctx.Param("ip") + ipAddr := net.ParseIP(ip) + if ipAddr == nil { + if ctx.ContentType() == "application/json" { + ctx.JSON(400, map[string]string{ + "message": "Provided IP is not valid", + }) + } else { + ctx.String(400, "Provided IP is not valid") + } + return + } + if !params.Trace { hosts, err := net.LookupAddr(ip) if err != nil || len(hosts) == 0 { @@ -54,7 +65,6 @@ func rdns(g group, log *zap.Logger, dnsServer string) { return } - ipAddr := net.ParseIP(ip) result, err := dnsLib.LookupRDNS( log, ipAddr, dnsServer, )