From f1a193b2c7375795487e212cc022f7a3c066634c Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Wed, 9 Feb 2022 12:59:40 -0500 Subject: linker/PEi386: Make addLibrarySearchPath long-path aware Previously `addLibrarySearchPath` failed to normalise the added path to UNC form before passing it to `AddDllDirectory`. Consequently, the call was subject to the MAX_PATH restriction, leading to the failure of `test-defaulting-plugin-fail`, among others. Happily, this also nicely simplifies the implementation. Closes #21059. --- rts/linker/PEi386.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/rts/linker/PEi386.c b/rts/linker/PEi386.c index e46949d9ea..684b02ac5b 100644 --- a/rts/linker/PEi386.c +++ b/rts/linker/PEi386.c @@ -767,21 +767,9 @@ pathchar* findSystemLibrary_PEi386( pathchar* dll_name ) HsPtr addLibrarySearchPath_PEi386(pathchar* dll_path) { - const unsigned int init_buf_size = 4096; - int bufsize = init_buf_size; - - // Make sure the path is an absolute path - WCHAR* abs_path = stgMallocBytes(sizeof(WCHAR) * init_buf_size, "addLibrarySearchPath_PEi386(1)"); - DWORD wResult = GetFullPathNameW(dll_path, bufsize, abs_path, NULL); - if (!wResult){ - IF_DEBUG(linker, debugBelch("addLibrarySearchPath[GetFullPathNameW]: %" PATH_FMT " (Win32 error %lu)", dll_path, GetLastError())); - } - else if (wResult > init_buf_size) { - abs_path = realloc(abs_path, sizeof(WCHAR) * wResult); - if (!GetFullPathNameW(dll_path, bufsize, abs_path, NULL)) { - IF_DEBUG(linker, debugBelch("addLibrarySearchPath[GetFullPathNameW]: %" PATH_FMT " (Win32 error %lu)", dll_path, GetLastError())); - } - } + // Make sure the path is an absolute path in UNC-style to ensure that we + // aren't subject to the MAX_PATH restriction. See #21059. + wchar_t *abs_path = __rts_create_device_name(dll_path); HsPtr result = AddDllDirectory(abs_path); if (!result) { -- cgit v1.2.1