-
Notifications
You must be signed in to change notification settings - Fork 263
Use safe DLL loading (avoid current directory) #1293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This avoids DLL planting issues during the fallback search for a base trust server. It uses the `LOAD_LIBRARY_SEARCH_DEFAULT_DIRS` flag, which searches the usual places, including the application directory, but exclude the current directory. The flag is supported on Win8 onward, as well as on Win7 if you have KB2533623 installed (which you really should). If you need to support versions of Win7 that haven't been patched since 2011, then stick with whatever version of C++/WinRT you are currently using.
|
Do we want to allow customization of the default, maybe via a #define? |
|
I'm not sure it's worth the expense of adding a customization switch to support operating systems that haven't been patched since 2011 |
|
Right, the switch is to use a different version of cppwinrt. |
|
For RNW we're going to do this: #ifdef CPPWINRT_USE_LOADLIBRARYEXW
#define WINRT_IMPL_LoadLibraryW(name) \
WINRT_IMPL_LoadLibraryExW(name, nullptr, 0x00001000 /* LOAD_LIBRARY_SEARCH_DEFAULT_DIRS */)
#endifwhere <ItemDefinitionGroup Label="CppWinRT">
<ClCompile>
<PreprocessorDefinitions Condition="$([MSBuild]::VersionGreaterThanOrEquals('$(CppWinRTVersion)', '2.0.230524.3'))">
CPPWINRT_USE_LOADLIBRARYEXW;
%(PreprocessorDefinitions)
</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>because of the lack of convenient version macros to do it strictly in code: #668. |
|
@jonthysell Note that all
If you want to call LoadLibrary, you can define your own |
…xW (#11953) ## Description CppWinRT >= 2.0.230524.3 no longer expose the `WINRT_IMPL_LoadLibraryW` method for loading libraries, instead preferring a new `WINRT_IMPL_LoadLibraryExW`. See microsoft/cppwinrt#1293. This PR fixes our usage of `WINRT_IMPL_LoadLibraryW` by detecting newer versions of CppWinRT and using the new API when available. ### Type of Change - Bug fix (non-breaking change which fixes an issue) ### Why Customers who tried to specify newer versions of CppWinRT hit build errors due to the use of the deprecated API. Closes #11795 ### What Created a macro to re-define the old API which calls the new API with the same behavior, as seen in the PR which deprecated the API in the first place. ## Screenshots N/A ## Testing Verified able to build against the latest [Microsoft.Windows.CppWinRT 2.0.230706.1](https://www.nuget.org/packages/Microsoft.Windows.CppWinRT/2.0.230706.1). ## Changelog Should this change be included in the release notes: yes Customers who specify their own version of Microsoft.Windows.CppWinRT can now use versions >= 2.0.230524.3.
…ibraryExW This PR backports microsoft#11953 to RNW 0.72. CppWinRT >= 2.0.230524.3 no longer expose the `WINRT_IMPL_LoadLibraryW` method for loading libraries, instead preferring a new `WINRT_IMPL_LoadLibraryExW`. See microsoft/cppwinrt#1293. This PR fixes our usage of `WINRT_IMPL_LoadLibraryW` by detecting newer versions of CppWinRT and using the new API when available. - Bug fix (non-breaking change which fixes an issue) Customers who tried to specify newer versions of CppWinRT hit build errors due to the use of the deprecated API. Closes microsoft#11795 Created a macro to re-define the old API which calls the new API with the same behavior, as seen in the PR which deprecated the API in the first place. N/A Verified able to build against the latest [Microsoft.Windows.CppWinRT 2.0.230706.1](https://www.nuget.org/packages/Microsoft.Windows.CppWinRT/2.0.230706.1). Should this change be included in the release notes: yes Customers who specify their own version of Microsoft.Windows.CppWinRT can now use versions >= 2.0.230524.3.
…ibraryExW This PR backports microsoft#11953 to RNW 0.72. CppWinRT >= 2.0.230524.3 no longer expose the `WINRT_IMPL_LoadLibraryW` method for loading libraries, instead preferring a new `WINRT_IMPL_LoadLibraryExW`. See microsoft/cppwinrt#1293. This PR fixes our usage of `WINRT_IMPL_LoadLibraryW` by detecting newer versions of CppWinRT and using the new API when available. - Bug fix (non-breaking change which fixes an issue) Customers who tried to specify newer versions of CppWinRT hit build errors due to the use of the deprecated API. Closes microsoft#11795 Created a macro to re-define the old API which calls the new API with the same behavior, as seen in the PR which deprecated the API in the first place. N/A Verified able to build against the latest [Microsoft.Windows.CppWinRT 2.0.230706.1](https://www.nuget.org/packages/Microsoft.Windows.CppWinRT/2.0.230706.1). Should this change be included in the release notes: yes Customers who specify their own version of Microsoft.Windows.CppWinRT can now use versions >= 2.0.230524.3. Enable using newer CppWinRT versions that use WINRT_IMPL_LoadLibraryExW (microsoft#11953) CppWinRT >= 2.0.230524.3 no longer expose the `WINRT_IMPL_LoadLibraryW` method for loading libraries, instead preferring a new `WINRT_IMPL_LoadLibraryExW`. See microsoft/cppwinrt#1293. This PR fixes our usage of `WINRT_IMPL_LoadLibraryW` by detecting newer versions of CppWinRT and using the new API when available. - Bug fix (non-breaking change which fixes an issue) Customers who tried to specify newer versions of CppWinRT hit build errors due to the use of the deprecated API. Closes microsoft#11795 Created a macro to re-define the old API which calls the new API with the same behavior, as seen in the PR which deprecated the API in the first place. N/A Verified able to build against the latest [Microsoft.Windows.CppWinRT 2.0.230706.1](https://www.nuget.org/packages/Microsoft.Windows.CppWinRT/2.0.230706.1). Should this change be included in the release notes: yes Customers who specify their own version of Microsoft.Windows.CppWinRT can now use versions >= 2.0.230524.3.
…ibraryExW (#11986) This PR backports #11953 to RNW 0.72. ## Description CppWinRT >= 2.0.230524.3 no longer expose the `WINRT_IMPL_LoadLibraryW` method for loading libraries, instead preferring a new `WINRT_IMPL_LoadLibraryExW`. See microsoft/cppwinrt#1293. This PR fixes our usage of `WINRT_IMPL_LoadLibraryW` by detecting newer versions of CppWinRT and using the new API when available. ### Type of Change - Bug fix (non-breaking change which fixes an issue) ### Why Customers who tried to specify newer versions of CppWinRT hit build errors due to the use of the deprecated API. Closes #11795 ### What Created a macro to re-define the old API which calls the new API with the same behavior, as seen in the PR which deprecated the API in the first place. ## Screenshots N/A ## Testing Verified able to build against the latest [Microsoft.Windows.CppWinRT 2.0.230706.1](https://www.nuget.org/packages/Microsoft.Windows.CppWinRT/2.0.230706.1). ## Changelog Should this change be included in the release notes: yes Customers who specify their own version of Microsoft.Windows.CppWinRT can now use versions >= 2.0.230524.3.
This avoids DLL planting issues during the fallback search for a base trust server. It uses the
LOAD_LIBRARY_SEARCH_DEFAULT_DIRSflag, which searches the usual places, including the application directory, but excludes the current directory. The flag is supported on Win8 onward, as well as on Win7 if you have KB2533623 installed (which you really should). If you need to support versions of Win7 that haven't been patched since 2011, then stick with whatever version of C++/WinRT you are currently using.