Skip to content

Commit

Permalink
asyn-thread: avoid using GetAddrInfoExW with impersonation
Browse files Browse the repository at this point in the history
Multiple reports suggest that GetAddrInfoExW fails when impersonation is
used. This PR checks if thread is impersonating and avoids using
GetAddrInfoExW api.

Reported-by: Keerthi Timmaraju
Assisted-by: edmcln on github
Fixes #13612
Closes #13738
  • Loading branch information
pps83 authored and bagder committed May 23, 2024
1 parent 30de937 commit 0caadc1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/asyn-thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,8 @@ static bool init_resolve_thread(struct Curl_easy *data,

#ifdef _WIN32
if(Curl_isWindows8OrGreater && Curl_FreeAddrInfoExW &&
Curl_GetAddrInfoExCancel && Curl_GetAddrInfoExW) {
Curl_GetAddrInfoExCancel && Curl_GetAddrInfoExW &&
!Curl_win32_impersonating()) {
#define MAX_NAME_LEN 256 /* max domain name is 253 chars */
#define MAX_PORT_LEN 8
WCHAR namebuf[MAX_NAME_LEN];
Expand Down
10 changes: 10 additions & 0 deletions lib/system_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,14 @@ HMODULE Curl_load_library(LPCTSTR filename)
#endif
}

bool Curl_win32_impersonating(void)
{
HANDLE token = NULL;
if(OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, TRUE, &token)) {
CloseHandle(token);
return TRUE;
}
return FALSE;
}

#endif /* _WIN32 */
2 changes: 2 additions & 0 deletions lib/system_win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ extern FREEADDRINFOEXW_FN Curl_FreeAddrInfoExW;
extern GETADDRINFOEXCANCEL_FN Curl_GetAddrInfoExCancel;
extern GETADDRINFOEXW_FN Curl_GetAddrInfoExW;

bool Curl_win32_impersonating(void);

/* This is used to dynamically load DLLs */
HMODULE Curl_load_library(LPCTSTR filename);
#else /* _WIN32 */
Expand Down

0 comments on commit 0caadc1

Please sign in to comment.