From c346220a76f4e5194cb6b30e992e098b7605eb4d Mon Sep 17 00:00:00 2001 From: Woongsuk Cho Date: Fri, 29 Mar 2024 06:58:08 +0900 Subject: [PATCH] Fix incorrect TPA error The isManagedAssembly() function receives a file name as an input and checks only the extension. But, it calls isR2RImage(), which requires a full path to the file internally. Upon checking the usage of the isManageAssembly() function, it is confirmed that it is used only to check whether it is a dll file or not. So, the isManagedAssembly() function has been modified to return true even in the case of including a native image, and related codes have been reorganized. --- NativeLauncher/inc/utils.h | 7 +++---- NativeLauncher/launcher/exec/corerun.cc | 2 +- NativeLauncher/tool/ni_common.cc | 4 ++-- NativeLauncher/util/utils.cc | 6 +++--- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/NativeLauncher/inc/utils.h b/NativeLauncher/inc/utils.h index dca091f..38c6361 100644 --- a/NativeLauncher/inc/utils.h +++ b/NativeLauncher/inc/utils.h @@ -159,10 +159,9 @@ bool isDirectory(const std::string& path); /** * @brief check the file is managed assembly or not. * @param[in] file path - * @return return true when the file is managed assembly. - * otherwise return false including native image case. - */ -bool isManagedAssembly(const std::string& filePath); + * @return return true when the file is managed assembly even if it includes a native image. + */ +bool isManagedAssembly(const std::string& fileName); /** * @brief Resolve assembly files from directories and append their paths to the given list. diff --git a/NativeLauncher/launcher/exec/corerun.cc b/NativeLauncher/launcher/exec/corerun.cc index 820679b..887912b 100644 --- a/NativeLauncher/launcher/exec/corerun.cc +++ b/NativeLauncher/launcher/exec/corerun.cc @@ -103,7 +103,7 @@ int main(int argc, const char* argv[]) { _SERR("Unknown option %s.", argv[0]); DisplayUsage(); return -1; - } else if (isManagedAssembly(arg) || isR2RImage(arg)) { + } else if (isManagedAssembly(arg)) { if (!isFile(arg)) { _SERR("The specified file does not exist."); return -1; diff --git a/NativeLauncher/tool/ni_common.cc b/NativeLauncher/tool/ni_common.cc index cf3a02b..36c2040 100644 --- a/NativeLauncher/tool/ni_common.cc +++ b/NativeLauncher/tool/ni_common.cc @@ -299,7 +299,7 @@ static bool checkDllExistInDir(const std::string& path) { bool ret = false; auto func = [&ret](const std::string& f_path, const std::string& f_name) { - if (isManagedAssembly(f_name) || isR2RImage(f_name)) { + if (isManagedAssembly(f_name)) { ret = true; } }; @@ -321,7 +321,7 @@ static ni_error_e getTargetDllList(const std::string& path, std::vector& directories, s std::unordered_map assemPaths; auto reader = [&assems, &assemPaths](const std::string& path, const std::string& filename) { - if (isManagedAssembly(filename) || isR2RImage(filename)) { + if (isManagedAssembly(filename)) { std::string assem = getAssemblyNameFromPath(filename); if (assemPaths.count(assem) == 0) { assems.push_back(assem); assemPaths[assem] = path; - } else if (isManagedAssembly(assemPaths[assem]) && isR2RImage(filename)) { + } else if (isR2RImage(path)) { // Update only if a native image is found in the same directory. // For example, if we have two directories = { X, Y } where X contains A.dll and // Y contains both A.dll and A.ni.dll, always A.dll in X will be used. -- 2.7.4