@@ -80,11 +80,9 @@ static std::wstring GetExecutablePath() {
8080 error_code_large);
8181 return std::wstring ();
8282 }
83- }
84- else {
83+ } else {
8584 // length >= buffer.size() but not ERROR_INSUFFICIENT_BUFFER.
86- LogError (LOG_TAG " Failed to get executable path. Error: %u" ,
87- error_code);
85+ LogError (LOG_TAG " Failed to get executable path. Error: %u" , error_code);
8886 return std::wstring ();
8987 }
9088 }
@@ -194,8 +192,7 @@ HMODULE VerifyAndLoadAnalyticsLibrary(
194192 }
195193 if (expected_hash == nullptr || expected_hash_size == 0 ) {
196194 // Don't check the hash, just load the library.
197- return LoadLibraryExW (library_filename, NULL ,
198- LOAD_LIBRARY_SEARCH_APPLICATION_DIR);
195+ return LoadLibraryW (library_filename);
199196 }
200197
201198 std::wstring executable_path_str = GetExecutablePath ();
@@ -262,14 +259,9 @@ HMODULE VerifyAndLoadAnalyticsLibrary(
262259 expected_hash_size) != 0 ) {
263260 LogError (LOG_TAG " Hash mismatch for Analytics DLL." );
264261 } else {
265- // Load the library. LOAD_LIBRARY_SEARCH_APPLICATION_DIR is a security
266- // measure to help ensure that the DLL is loaded from the application's
267- // installation directory, mitigating risks of DLL preloading attacks
268- // from other locations. Crucially, LoadLibraryExW with this flag needs
269- // the DLL *filename only* (library_filename), not the full path we
270- // constructed for CreateFileW.
271- hModule = LoadLibraryExW (library_filename, NULL ,
272- LOAD_LIBRARY_SEARCH_APPLICATION_DIR);
262+ // Load the library. When loading with a full path string, other
263+ // directories are not searched.
264+ hModule = LoadLibraryW (full_dll_path_str);
273265 if (hModule == NULL ) {
274266 DWORD dwError = GetLastError ();
275267 LogError (LOG_TAG " Library load failed for Analytics DLL. Error: %u" ,
0 commit comments