Commit 2f99450c authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

wininet: Make resolving hostnames thread-safe.

parent 7cdc50fe
......@@ -1346,6 +1346,8 @@ static BOOL HTTP_ResolveName(LPWININETHTTPREQW lpwhr)
INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
INTERNET_STATUS_NAME_RESOLVED,
szaddr, strlen(szaddr)+1);
TRACE("resolved %s to %s\n", debugstr_w(lpwhs->lpszServerName), szaddr);
return TRUE;
}
......@@ -3607,7 +3609,7 @@ static BOOL HTTP_OpenConnection(LPWININETHTTPREQW lpwhr)
if (!NETCON_create(&lpwhr->netConnection, lpwhs->socketAddress.sin_family,
SOCK_STREAM, 0))
{
WARN("Socket creation failed\n");
WARN("Socket creation failed: %u\n", INTERNET_GetLastError());
goto lend;
}
......
......@@ -40,6 +40,16 @@
WINE_DEFAULT_DEBUG_CHANNEL(wininet);
/* critical section to protect non-reentrant gethostbyname() */
static CRITICAL_SECTION cs_gethostbyname;
static CRITICAL_SECTION_DEBUG critsect_debug =
{
0, 0, &cs_gethostbyname,
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
0, 0, { (DWORD_PTR)(__FILE__ ": cs_gethostbyname") }
};
static CRITICAL_SECTION cs_gethostbyname = { &critsect_debug, -1, 0, 0, 0, 0 };
#define TIME_STRING_LEN 30
time_t ConvertTimeString(LPCWSTR asctime)
......@@ -151,12 +161,15 @@ BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
name = HeapAlloc(GetProcessHeap(), 0, sz+1);
WideCharToMultiByte( CP_UNIXCP, 0, lpszServerName, len, name, sz, NULL, NULL );
name[sz] = 0;
EnterCriticalSection( &cs_gethostbyname );
phe = gethostbyname(name);
HeapFree( GetProcessHeap(), 0, name );
if (NULL == phe)
{
TRACE("Failed to get hostname: (%s)\n", debugstr_w(lpszServerName) );
LeaveCriticalSection( &cs_gethostbyname );
return FALSE;
}
......@@ -165,6 +178,7 @@ BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
psa->sin_family = phe->h_addrtype;
psa->sin_port = htons(nServerPort);
LeaveCriticalSection( &cs_gethostbyname );
return TRUE;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment