diff --git a/examples/nft-nd-nns/nns.go b/examples/nft-nd-nns/nns.go index 90ffa08cf..0236dcd6a 100644 --- a/examples/nft-nd-nns/nns.go +++ b/examples/nft-nd-nns/nns.go @@ -716,6 +716,12 @@ func resolve(ctx storage.Context, name string, typ RecordType, redirect int) str if redirect < 0 { panic("invalid redirect") } + if len(name) == 0 { + panic("invalid name") + } + if name[len(name)-1] == '.' { + name = name[:len(name)-1] + } records := getRecords(ctx, name) cname := "" for iterator.Next(records) { diff --git a/examples/nft-nd-nns/nns_test.go b/examples/nft-nd-nns/nns_test.go index 983db3474..e4e9bf21b 100644 --- a/examples/nft-nd-nns/nns_test.go +++ b/examples/nft-nd-nns/nns_test.go @@ -451,6 +451,8 @@ func TestResolve(t *testing.T) { c.Invoke(t, "1.2.3.4", "resolve", "neo.com", int64(nns.A)) c.Invoke(t, "alias.com", "resolve", "neo.com", int64(nns.CNAME)) c.Invoke(t, "sometxt", "resolve", "neo.com", int64(nns.TXT)) + c.Invoke(t, "sometxt", "resolve", "neo.com.", int64(nns.TXT)) + c.InvokeFail(t, "invalid domain name format", "resolve", "neo.com..", int64(nns.TXT)) c.Invoke(t, stackitem.Null{}, "resolve", "neo.com", int64(nns.AAAA)) }