From a0b247cdc0cfff55c7966fc99ce62bd6cfe2c309 Mon Sep 17 00:00:00 2001 From: Vilmos Nebehaj Date: Fri, 21 Mar 2014 14:36:15 +0100 Subject: [PATCH 1/2] Load hosts file on Windows. Hosts files are not loaded in evdns_base_config_windows_nameservers() if load_nameservers_with_getnetworkparams() succeeds on Windows. Parse and load it first before setting up nameservers. --- evdns.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/evdns.c b/evdns.c index 59c3abe1..a143074d 100644 --- a/evdns.c +++ b/evdns.c @@ -3826,17 +3826,18 @@ evdns_base_config_windows_nameservers(struct evdns_base *base) if (base == NULL) return -1; EVDNS_LOCK(base); + fname = evdns_get_default_hosts_filename(); + log(EVDNS_LOG_DEBUG, "Loading hosts entries from %s", fname); + evdns_base_load_hosts(base, fname); + if (fname) + mm_free(fname); + if (load_nameservers_with_getnetworkparams(base) == 0) { EVDNS_UNLOCK(base); return 0; } r = load_nameservers_from_registry(base); - fname = evdns_get_default_hosts_filename(); - evdns_base_load_hosts(base, fname); - if (fname) - mm_free(fname); - EVDNS_UNLOCK(base); return r; } From d0dc861b881e129ab9afb26cfe5df99187eeb53d Mon Sep 17 00:00:00 2001 From: Vilmos Nebehaj Date: Fri, 21 Mar 2014 14:38:11 +0100 Subject: [PATCH 2/2] Don't truncate hosts file path on Windows. Since evutil_snprintf() (actually evutil_vsnprintf() called by it) will make sure the buffer is null-terminated by placing a null byte at len_out - 1, we need to pass the full length of the buffer; otherwise the path will end in "\\host" instead of "\\hosts". --- evdns.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/evdns.c b/evdns.c index a143074d..a1d8c95a 100644 --- a/evdns.c +++ b/evdns.c @@ -3555,8 +3555,8 @@ evdns_get_default_hosts_filename(void) if (! SHGetSpecialFolderPathA(NULL, path, CSIDL_SYSTEM, 0)) return NULL; - len_out = strlen(path)+strlen(hostfile); - path_out = mm_malloc(len_out+1); + len_out = strlen(path)+strlen(hostfile)+1; + path_out = mm_malloc(len_out); evutil_snprintf(path_out, len_out, "%s%s", path, hostfile); return path_out; #else