Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Avoid socket failure with missing SYSTEMROOT env var on Windows. Patch by
John Keith Hohm.
19 changes: 19 additions & 0 deletions Modules/socketmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,21 @@ remove_unusable_flags(PyObject *m)
return 0;
}

/* issue #118234, avoid WinError 10106 with empty environment */
static void ensure_system_root() {
LPCWSTR name = L"SystemRoot";
DWORD size = GetEnvironmentVariableW(name, NULL, 0);
if (size) {
return;
}
wchar_t root[4096];
UINT len = GetWindowsDirectoryW(root, 4096);
if (len == 0 || len >= 4096) {
return;
}
SetEnvironmentVariableW(name, root);
}

#endif

#include <stddef.h>
Expand Down Expand Up @@ -5618,6 +5633,10 @@ sock_initobj_impl(PySocketSockObject *self, int family, int type, int proto,
SOCKET_T fd = INVALID_SOCKET;
socket_state *state = find_module_state_by_def(Py_TYPE(self));

#ifdef MS_WINDOWS
ensure_system_root();
#endif

#ifndef MS_WINDOWS
#ifdef SOCK_CLOEXEC
int *atomic_flag_works = &sock_cloexec_works;
Expand Down
Loading