From 4bc7eee909b7fd6b59e2409456cd533b6c5795da Mon Sep 17 00:00:00 2001 From: Will Toohey Date: Sun, 17 Nov 2019 15:08:25 +1000 Subject: [PATCH] Allow dns hook to fail a resolve and add domains This lets people with crap ISPs that resolve domains that they shouldn't to use the game without changing their DNS server --- hooklib/dns.c | 35 ++++++++++++++++++++++++++++++----- hooklib/dns.h | 1 + platform/dns.c | 15 +++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/hooklib/dns.c b/hooklib/dns.c index 04699d3..aac90ce 100644 --- a/hooklib/dns.c +++ b/hooklib/dns.c @@ -156,7 +156,6 @@ HRESULT dns_hook_push(const wchar_t *from_src, const wchar_t *to_src) wchar_t *to; assert(from_src != NULL); - assert(to_src != NULL); to = NULL; from = NULL; @@ -172,12 +171,14 @@ HRESULT dns_hook_push(const wchar_t *from_src, const wchar_t *to_src) goto end; } - to = _wcsdup(to_src); + if(to_src != NULL) { + to = _wcsdup(to_src); - if (to == NULL) { - hr = E_OUTOFMEMORY; + if (to == NULL) { + hr = E_OUTOFMEMORY; - goto end; + goto end; + } } newmem = realloc( @@ -250,6 +251,13 @@ static DNS_STATUS WINAPI hook_DnsQuery_A( pos = &dns_hook_entries[i]; if (_wcsicmp(wstr, pos->from) == 0) { + if(pos->to == NULL) { + LeaveCriticalSection(&dns_hook_lock); + hr = HRESULT_FROM_WIN32(DNS_ERROR_RCODE_NAME_ERROR); + + goto end; + } + wcstombs_s(&str_c, NULL, 0, pos->to, 0); str = malloc(str_c * sizeof(char)); @@ -307,6 +315,11 @@ static DNS_STATUS WINAPI hook_DnsQuery_W( pos = &dns_hook_entries[i]; if (_wcsicmp(pszName, pos->from) == 0) { + if(pos->to == NULL) { + LeaveCriticalSection(&dns_hook_lock); + return HRESULT_FROM_WIN32(DNS_ERROR_RCODE_NAME_ERROR); + } + pszName = pos->to; break; @@ -346,6 +359,11 @@ static DNS_STATUS WINAPI hook_DnsQueryEx( pos = &dns_hook_entries[i]; if (_wcsicmp(pRequest->QueryName, pos->from) == 0) { + if(pos->to == NULL) { + LeaveCriticalSection(&dns_hook_lock); + return HRESULT_FROM_WIN32(DNS_ERROR_RCODE_NAME_ERROR); + } + pRequest->QueryName = pos->to; break; @@ -408,6 +426,13 @@ static int WSAAPI hook_getaddrinfo( pos = &dns_hook_entries[i]; if (_wcsicmp(wstr, pos->from) == 0) { + if(pos->to == NULL) { + LeaveCriticalSection(&dns_hook_lock); + result = EAI_NONAME; + + goto end; + } + wcstombs_s(&str_c, NULL, 0, pos->to, 0); str = malloc(str_c * sizeof(char)); diff --git a/hooklib/dns.h b/hooklib/dns.h index 062d481..1f93b0f 100644 --- a/hooklib/dns.h +++ b/hooklib/dns.h @@ -4,5 +4,6 @@ #include +// if to_src is NULL, all lookups for from_src will fail HRESULT dns_hook_push(const wchar_t *from_src, const wchar_t *to_src); diff --git a/platform/dns.c b/platform/dns.c index 51f64f8..5486d42 100644 --- a/platform/dns.c +++ b/platform/dns.c @@ -64,5 +64,20 @@ HRESULT dns_platform_hook_init(const struct dns_config *cfg) return hr; } + // if your ISP resolves bad domains, it will kill the network. These 2 + // *cannot* resolve + + hr = dns_hook_push(L"mobirouter.loc", NULL); + + if (FAILED(hr)) { + return hr; + } + + hr = dns_hook_push(L"dslrouter.loc", NULL); + + if (FAILED(hr)) { + return hr; + } + return S_OK; }