diff options
-rw-r--r-- | gtests/pk11_gtest/pk11_module_unittest.cc | 41 | ||||
-rw-r--r-- | lib/pk11wrap/pk11load.c | 22 |
2 files changed, 61 insertions, 2 deletions
diff --git a/gtests/pk11_gtest/pk11_module_unittest.cc b/gtests/pk11_gtest/pk11_module_unittest.cc index 41ce8c086..eb467c3c4 100644 --- a/gtests/pk11_gtest/pk11_module_unittest.cc +++ b/gtests/pk11_gtest/pk11_module_unittest.cc @@ -81,4 +81,45 @@ TEST_F(Pkcs11ModuleTest, PublicCertificatesToken) { EXPECT_TRUE(PK11_IsFriendly(slot2.get())); } +#if defined(_WIN32) +#include <windows.h> + +class Pkcs11NonAsciiTest : public ::testing::Test { + WCHAR nonAsciiModuleName[MAX_PATH]; + + public: + Pkcs11NonAsciiTest() {} + + void SetUp() override { + WCHAR originalModuleName[MAX_PATH]; + LPWSTR filePart; + DWORD count = SearchPathW(NULL, L"pkcs11testmodule.dll", NULL, MAX_PATH, + nonAsciiModuleName, &filePart); + ASSERT_TRUE(count); + wcscpy(originalModuleName, nonAsciiModuleName); + wcscpy(filePart, L"pkcs11testmodule\u2665.dll"); + BOOL result = CopyFileW(originalModuleName, nonAsciiModuleName, TRUE); + ASSERT_TRUE(result); + ASSERT_EQ(SECSuccess, + SECMOD_AddNewModule("Pkcs11NonAsciiTest", DLL_PREFIX + "pkcs11testmodule\xE2\x99\xA5." DLL_SUFFIX, + 0, 0)) + << PORT_ErrorToName(PORT_GetError()); + } + + void TearDown() override { + int type; + ASSERT_EQ(SECSuccess, SECMOD_DeleteModule("Pkcs11NonAsciiTest", &type)); + ASSERT_EQ(SECMOD_EXTERNAL, type); + BOOL result = DeleteFileW(nonAsciiModuleName); + ASSERT_TRUE(result); + } +}; + +TEST_F(Pkcs11NonAsciiTest, LoadUnload) { + ScopedSECMODModule module(SECMOD_FindModule("Pkcs11NonAsciiTest")); + EXPECT_NE(nullptr, module); +} +#endif // defined(_WIN32) + } // namespace nss_test diff --git a/lib/pk11wrap/pk11load.c b/lib/pk11wrap/pk11load.c index a318e92fa..119c8c512 100644 --- a/lib/pk11wrap/pk11load.c +++ b/lib/pk11wrap/pk11load.c @@ -6,6 +6,7 @@ * various PCKS #11 modules */ #define FORCE_PR_LOG 1 +#include "base.h" #include "seccomon.h" #include "pkcs11.h" #include "secmod.h" @@ -16,7 +17,7 @@ #include "nssilock.h" #include "secerr.h" #include "prenv.h" -#include "utilparst.h" +#include "utilpars.h" #include "prio.h" #include "prprf.h" #include <stdio.h> @@ -464,10 +465,27 @@ secmod_LoadPKCS11Module(SECMODModule *mod, SECMODModule **oldModule) return SECFailure; } - /* load the library. If this succeeds, then we have to remember to +/* load the library. If this succeeds, then we have to remember to * unload the library if anything goes wrong from here on out... */ +#if defined(_WIN32) + if (nssUTF8_Length(mod->dllName, NULL)) { + wchar_t *dllNameWide = _NSSUTIL_UTF8ToWide(mod->dllName); + if (dllNameWide) { + PRLibSpec libSpec; + libSpec.type = PR_LibSpec_PathnameU; + libSpec.value.pathname_u = dllNameWide; + library = PR_LoadLibraryWithFlags(libSpec, 0); + PORT_Free(dllNameWide); + } + } + if (library == NULL) { + // fallback to system code page + library = PR_LoadLibrary(mod->dllName); + } +#else library = PR_LoadLibrary(mod->dllName); +#endif // defined(_WIN32) mod->library = (void *)library; if (library == NULL) { |