已合并
fix(kernel_mgr): 修复 ASAN 场景下 LoadStaticBinJson 抛异常时卡死的问题 #689
ren-botao创建于 7月31日
fix(kernel_mgr): 修复 ASAN 场景下 LoadStaticBinJson 抛异常时卡死的问题 #689
已合并
共 1 个文件变更+7-4
| @@ -78,7 +78,7 @@ aclnnStatus KernelMgr::LoadStaticBinJson() | |||
| 78 | { | 78 | { |
| 79 | staticConfigJson_.clear(); | 79 | staticConfigJson_.clear(); |
| 80 | 80 | ||
| 81 | - string staticKernelBasePath; | 81 | + std::string staticKernelBasePath; |
| 82 | if (!customStaticKernelBasePath_.empty()) { | 82 | if (!customStaticKernelBasePath_.empty()) { |
| 83 | // 路径已在 aclnnReselectStaticKernelWithPath 入口做过 RealPath 校验 | 83 | // 路径已在 aclnnReselectStaticKernelWithPath 入口做过 RealPath 校验 |
| 84 | OP_LOGI("Load static bin json from custom base path: %s", customStaticKernelBasePath_.c_str()); | 84 | OP_LOGI("Load static bin json from custom base path: %s", customStaticKernelBasePath_.c_str()); |
| @@ -90,18 +90,21 @@ aclnnStatus KernelMgr::LoadStaticBinJson() | |||
| 90 | OP_LOGE_FOR_CONFIG_ERROR_INVALID_ENVIRONMENT_VARIABLE("Loading static bin json", "ASCEND_OPP_PATH"), | 90 | OP_LOGE_FOR_CONFIG_ERROR_INVALID_ENVIRONMENT_VARIABLE("Loading static bin json", "ASCEND_OPP_PATH"), |
| 91 | return ACLNN_ERR_INNER_OPP_PATH_NOT_FOUND); | 91 | return ACLNN_ERR_INNER_OPP_PATH_NOT_FOUND); |
| 92 | } | 92 | } |
| 93 | - string configJsonPath = staticKernelBasePath; | 93 | + std::string configJsonPath = staticKernelBasePath; |
| 94 | auto& knlLib = OpKernelLib::GetInstance(); | 94 | auto& knlLib = OpKernelLib::GetInstance(); |
| 95 | configJsonPath.append(STATIC_CONFIG_JSON_PATH); | 95 | configJsonPath.append(STATIC_CONFIG_JSON_PATH); |
| 96 | configJsonPath.append(knlLib.GetSocPath()); | 96 | configJsonPath.append(knlLib.GetSocPath()); |
| 97 | configJsonPath.append(STATIC_CONFIG_FILE_NAME); | 97 | configJsonPath.append(STATIC_CONFIG_FILE_NAME); |
| 98 | staticBinAndJsonDir_ = staticKernelBasePath; | 98 | staticBinAndJsonDir_ = staticKernelBasePath; |
| 99 | staticBinAndJsonDir_.append(STATIC_BIN_AND_JSON_DIR_PATH); | 99 | staticBinAndJsonDir_.append(STATIC_BIN_AND_JSON_DIR_PATH); |
| 100 | - ifstream f(configJsonPath); | 100 | + std::string realConfigJsonPath = RealPath(configJsonPath); |
| 101 | + OP_CHECK(!realConfigJsonPath.empty(), | ||
| 102 | + OP_LOGW("static kernel config json is not exist, path: %s", configJsonPath.c_str()), return ACLNN_SUCCESS); | ||
| 103 | + ifstream f(realConfigJsonPath); | ||
| 101 | try { | 104 | try { |
| 102 | staticConfigJson_ = nlohmann::json::parse(f); | 105 | staticConfigJson_ = nlohmann::json::parse(f); |
| 103 | } catch (nlohmann::json::exception& e) { | 106 | } catch (nlohmann::json::exception& e) { |
| 104 | - OP_LOGW("Cannot parse static json for config file [%s] because %s.", configJsonPath.c_str(), e.what()); | 107 | + OP_LOGW("Cannot parse static json for config file [%s] because %s.", realConfigJsonPath.c_str(), e.what()); |
| 105 | return ACLNN_SUCCESS; | 108 | return ACLNN_SUCCESS; |
| 106 | } | 109 | } |
| 107 | return ACLNN_SUCCESS; | 110 | return ACLNN_SUCCESS; |