From 697c6c6893bfe22a31420953232c982a691025d6 Mon Sep 17 00:00:00 2001 From: Tau Date: Sat, 7 Sep 2019 16:25:44 -0400 Subject: [PATCH] hooklib/dns.c: Fix locking --- hooklib/dns.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hooklib/dns.c b/hooklib/dns.c index b8e58d2..221c7fc 100644 --- a/hooklib/dns.c +++ b/hooklib/dns.c @@ -216,6 +216,7 @@ static DNS_STATUS WINAPI hook_DnsQuery_A( } mbstowcs_s(NULL, wstr, wstr_c, pszName, wstr_c - 1); + EnterCriticalSection(&dns_hook_lock); for (i = 0 ; i < dns_hook_nentries ; i++) { pos = &dns_hook_entries[i]; @@ -225,6 +226,7 @@ static DNS_STATUS WINAPI hook_DnsQuery_A( str = malloc(str_c * sizeof(char)); if (str == NULL) { + LeaveCriticalSection(&dns_hook_lock); hr = HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY); goto end; @@ -237,6 +239,8 @@ static DNS_STATUS WINAPI hook_DnsQuery_A( } } + LeaveCriticalSection(&dns_hook_lock); + code = next_DnsQuery_A( pszName, wType, @@ -269,6 +273,8 @@ static DNS_STATUS WINAPI hook_DnsQuery_W( return ERROR_INVALID_PARAMETER; } + EnterCriticalSection(&dns_hook_lock); + for (i = 0 ; i < dns_hook_nentries ; i++) { pos = &dns_hook_entries[i]; @@ -279,6 +285,8 @@ static DNS_STATUS WINAPI hook_DnsQuery_W( } } + LeaveCriticalSection(&dns_hook_lock); + return next_DnsQuery_W( pszName, wType, @@ -304,6 +312,7 @@ static DNS_STATUS WINAPI hook_DnsQueryEx( } orig = pRequest->QueryName; + EnterCriticalSection(&dns_hook_lock); for (i = 0 ; i < dns_hook_nentries ; i++) { pos = &dns_hook_entries[i]; @@ -315,6 +324,8 @@ static DNS_STATUS WINAPI hook_DnsQueryEx( } } + LeaveCriticalSection(&dns_hook_lock); + code = next_DnsQueryEx(pRequest, pQueryResults, pCancelHandle); /* Caller might not appreciate QueryName changing under its feet. It is