#2850 defect new
getHostByName Error when DNS Server return Name Server
|Reported by:||wangminghua||Owned by:|
Description (last modified by )
Python Version:2.5 Twisted Version:2.5 Names Version:0.4 There is a bug in the extractRecord function of common.py.
When we got a resolver and call getHostByname, perhaps DNS server can return CNAME, Auth NS Server Name and Auth NS Server IP Address. So extractRecord function will extract the Auth NS Server and send the DNS request to the Auth NS Server. But there is a bug in the extractRecord function.
# No answers, but maybe there's a hint at who we should be asking about this for r in answers: if r.type == dns.NS: from twisted.names import client r = client.Resolver(servers=[(str(r.payload.name), dns.PORT)]) return r.lookupAddress(str(name)
Generally, the Auth NS Server is the Domain name, and it's IP contained in the addition fields. If we get the NS Server by r.payload.name, we will get the DNS Server Domain, so the Domain as server will pass to client.queryUDP as DNS Server Address. UDP.write will complaint that warnings.warn("Please only pass IPs to write(), not hostnames "+addr, DeprecationWarning, stacklevel=2). In addition, self.socket.sendto(datagram, addr) will call socket.gethostbyname(addr), but this call is block.
I think we should use the Auth NS Server IP to replace the Domain. The patch code as fellow:
# No answers, but maybe there's a hint at who we should be asking about this for r in answers: if r.type == dns.NS: from twisted.names import client server = str(r.payload.name) for s in answers: if s.type==dns.A and str(s.name)==nsServerName: server = socket.inet_ntop(socket.AF_INET, s.payload.address) break r = client.Resolver(servers=[(server, dns.PORT)])