From 9147a19d2469b9a641d51c37d33bf874311f8e94 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Sun, 30 Mar 2025 13:57:06 +0100 Subject: [PATCH] Use osl_getEnvironment instead of getenv Avoids conversion to OUString; and is Unicode-safe on Windows. Change-Id: Idd82f589ae9bf692ce2e73f84cb664a68156915a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183507 Reviewed-by: Mike Kaganski Tested-by: Jenkins --- xmlsecurity/source/xmlsec/nss/nssinitializer.cxx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/xmlsecurity/source/xmlsec/nss/nssinitializer.cxx b/xmlsecurity/source/xmlsec/nss/nssinitializer.cxx index 4c74aaddf449..23227b49c7a6 100644 --- a/xmlsecurity/source/xmlsec/nss/nssinitializer.cxx +++ b/xmlsecurity/source/xmlsec/nss/nssinitializer.cxx @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -176,13 +177,13 @@ const OUString & ONSSInitializer::getMozillaCurrentProfile(const css::uno::Refer m_bIsNSSinitialized = true; // first, try to get the profile from "MOZILLA_CERTIFICATE_FOLDER" - const char* pEnv = getenv("MOZILLA_CERTIFICATE_FOLDER"); - if (pEnv) + if (OUString pEnv; osl_getEnvironment(u"MOZILLA_CERTIFICATE_FOLDER"_ustr.pData, &pEnv.pData) == osl_Process_E_None + && !pEnv.isEmpty()) { SAL_INFO( "xmlsecurity.xmlsec", "Using Mozilla profile from MOZILLA_CERTIFICATE_FOLDER=" << pEnv); - m_sNSSPath = OStringToOUString(pEnv, osl_getThreadTextEncoding()); + m_sNSSPath = pEnv; } // second, try to get saved user-preference @@ -284,9 +285,10 @@ css::uno::Sequence SAL_CALL ONSSInitializer::getNS } aProfileList.push_back({u"MANUAL"_ustr, sUserSelect, mozilla::MozillaProductType_Default}); - const char* pEnv = getenv("MOZILLA_CERTIFICATE_FOLDER"); + OUString pEnv; + osl_getEnvironment(u"MOZILLA_CERTIFICATE_FOLDER"_ustr.pData, &pEnv.pData); aProfileList.push_back({u"MOZILLA_CERTIFICATE_FOLDER"_ustr, - pEnv ? OStringToOUString(pEnv, osl_getThreadTextEncoding()) : OUString(), + pEnv, mozilla::MozillaProductType_Default}); return comphelper::containerToSequence(aProfileList);