diff --git a/interfaces/innerkits/appverify/BUILD.gn b/interfaces/innerkits/appverify/BUILD.gn index d1918f67e90a4e79b7b5ac00bb4e58beb497b035..19b15c909fa88d9ea68b2b5e0408d3ba9b030d08 100644 --- a/interfaces/innerkits/appverify/BUILD.gn +++ b/interfaces/innerkits/appverify/BUILD.gn @@ -17,6 +17,7 @@ if (os_level == "standard") { config("libhapverify_config") { visibility = [ ":*" ] include_dirs = [ "include" ] + configs = [ "//build/config/compiler:exceptions" ] } ohos_shared_library("libhapverify") { @@ -60,6 +61,7 @@ if (os_level == "standard") { cflags_cc = [ "-DHILOG_ENABLE", "-fvisibility=hidden", + "-fexceptions", ] deps = [] diff --git a/interfaces/innerkits/appverify/src/verify/hap_verify_v2.cpp b/interfaces/innerkits/appverify/src/verify/hap_verify_v2.cpp index 829f35b497adbed3e25296777c28dc86b3b6cbaa..89a2a4ec08f1bcf36b33628118102d1c272d5a78 100644 --- a/interfaces/innerkits/appverify/src/verify/hap_verify_v2.cpp +++ b/interfaces/innerkits/appverify/src/verify/hap_verify_v2.cpp @@ -67,10 +67,18 @@ bool HapVerifyV2::CheckFilePath(const std::string& filePath, std::string& standa return false; } standardFilePath = std::string(path); - if (!std::regex_match(standardFilePath, std::regex(HAP_APP_PATTERN)) && - !std::regex_match(standardFilePath, std::regex(HSP_APP_PATTERN)) && - !std::regex_match(standardFilePath, std::regex(HQF_APP_PATTERN))) { - HAPVERIFY_LOG_ERROR("file is not hap, hsp or hqf package"); + try { + if (!std::regex_match(standardFilePath, std::regex(HAP_APP_PATTERN)) && + !std::regex_match(standardFilePath, std::regex(HSP_APP_PATTERN)) && + !std::regex_match(standardFilePath, std::regex(HQF_APP_PATTERN))) { + HAPVERIFY_LOG_ERROR("file is not hap, hsp or hqf package"); + return false; + } + } catch(const std::regex_error& e) { + HAPVERIFY_LOG_ERROR("regex match error"); + return false; + } catch(...) { + HAPVERIFY_LOG_ERROR("unexpected error"); return false; } return true;