mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
Fix IPv4 DNS lookup bug
In revision 1.15 of dns.c (as it was called way back then), pasky backported a fix from Links 0.97pre2 to try gethostbyaddr before trying gethostbyname for DNS lookups: MacOS address resolution fix (Aldy Hernandez) (from 0.97pre2) However, that fix introduced a bug, because it was calling gethostbyaddr on all addresses, not just IP addresses. Mikulas fixed that bug in Links 0.98: Do not call gethostbyaddr when name is not ip address (it should avoid some useless nameserver queries)' This fix was never backported to ELinks. Until today. This commit is functionally the same as the fix in Links 0.98, plus it uses inet_aton for great correctness! This fixes a bug reported in #elinks by tnks, whereby lookups for yubnub.org resulted in 121.117.98.110 == 0x7975626E == 'y', 'u', 'b', 'n'. I believe that it also fixes bug 691 (which is already closed with a workaround).
This commit is contained in:
parent
44633cd757
commit
8344dfe6c9
@ -34,6 +34,7 @@
|
||||
#include "main/select.h"
|
||||
#include "network/dns.h"
|
||||
#include "osdep/osdep.h"
|
||||
#include "protocol/uri.h"
|
||||
#include "util/error.h"
|
||||
#include "util/memory.h"
|
||||
#include "util/time.h"
|
||||
@ -143,7 +144,7 @@ do_real_lookup(unsigned char *name, struct sockaddr_storage **addrs, int *addrno
|
||||
#ifdef CONFIG_IPV6
|
||||
struct addrinfo hint, *ai, *ai_cur;
|
||||
#else
|
||||
struct hostent *hostent;
|
||||
struct hostent *hostent = NULL;
|
||||
#endif
|
||||
int i;
|
||||
|
||||
@ -165,7 +166,12 @@ do_real_lookup(unsigned char *name, struct sockaddr_storage **addrs, int *addrno
|
||||
* gethostbyaddr(), but there are problems with gethostbyaddr on Cygwin,
|
||||
* so we do not use gethostbyaddr there. */
|
||||
#if defined(HAVE_GETHOSTBYADDR) && !defined(HAVE_SYS_CYGWIN_H)
|
||||
hostent = gethostbyaddr(name, strlen(name), AF_INET);
|
||||
{
|
||||
struct in_addr inp;
|
||||
|
||||
if (is_ip_address(name, strlen(name)) && inet_aton(name, &inp))
|
||||
hostent = gethostbyaddr(&inp, sizeof(inp), AF_INET);
|
||||
}
|
||||
if (!hostent)
|
||||
#endif
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user