diff --git a/hapsigntool_cpp/cmd/src/cmd_util.cpp b/hapsigntool_cpp/cmd/src/cmd_util.cpp index e17b973f541acfee7f1e5149134409f87a1083af..1d87240d32e5b6728d6ffee723922fd61bb869c9 100644 --- a/hapsigntool_cpp/cmd/src/cmd_util.cpp +++ b/hapsigntool_cpp/cmd/src/cmd_util.cpp @@ -52,10 +52,7 @@ static bool UpdateParamForVariantCertInt(ParamsSharedPtr param) return false; } } - try { - validity = stoi(val); - } - catch (std::exception& e) { + if (!StringUtils::CheckStringToint(val, validity)) { PrintErrorNumberMsg("COMMAND_PARAM_ERROR", COMMAND_PARAM_ERROR, "Invalid parameter '" + val + "', You should fill in the numbers"); return false; @@ -92,10 +89,7 @@ static bool UpdateParamForVariantInt(ParamsSharedPtr param) if (options->count(Options::BASIC_CONSTRAINTS_PATH_LEN)) { int basicConstraintsPathLen = 0; std::string val = options->GetString(Options::BASIC_CONSTRAINTS_PATH_LEN); - try { - basicConstraintsPathLen = stoi(val); - } - catch (std::exception& e) { + if (!StringUtils::CheckStringToint(val, basicConstraintsPathLen)) { PrintErrorNumberMsg("COMMAND_PARAM_ERROR", COMMAND_PARAM_ERROR, "Invalid parameter '" + val + "', You should fill in the numbers"); return false; diff --git a/hapsigntool_cpp/codesigning/fsverity/include/thread_pool.h b/hapsigntool_cpp/codesigning/fsverity/include/thread_pool.h index a995bf8d563cce769814ec31d66f40726e083ce9..9c9684a9993f77c6b8d11c393c754364af469057 100644 --- a/hapsigntool_cpp/codesigning/fsverity/include/thread_pool.h +++ b/hapsigntool_cpp/codesigning/fsverity/include/thread_pool.h @@ -64,9 +64,6 @@ public: std::future res = task->get_future(); { std::unique_lock lock(queue_mutex); - // don't allow enqueueing after stopping the pool - if (stop) - throw std::runtime_error("enqueue on stopped ThreadPool"); while (stop == false && tasks.size() >= TASK_NUM) condition_max.wait(lock); tasks.emplace([task] () { (*task)(); }); diff --git a/hapsigntool_cpp/common/src/byte_buffer.cpp b/hapsigntool_cpp/common/src/byte_buffer.cpp index 5f7dabf52142b7bad34014813bb42c0579c8e91d..447b210b19a6551032352a2ce64b8754c55c6f06 100644 --- a/hapsigntool_cpp/common/src/byte_buffer.cpp +++ b/hapsigntool_cpp/common/src/byte_buffer.cpp @@ -27,8 +27,9 @@ const int32_t ByteBuffer::HEX_PRINT_LENGTH = 3; template std::shared_ptr make_shared_array(size_t size) { - if (size <= 0) + if (size <= 0) { return NULL; + } T* buffer = new (std::nothrow)T[size]; if (!buffer) { SIGNATURE_TOOLS_LOGE("new size failed"); diff --git a/hapsigntool_cpp/utils/include/string_utils.h b/hapsigntool_cpp/utils/include/string_utils.h index ab8a253b38bf4eecb17b29e4493ec1481ff677bf..44122ee3299baff9542b9f198fcacb2c0833c320 100644 --- a/hapsigntool_cpp/utils/include/string_utils.h +++ b/hapsigntool_cpp/utils/include/string_utils.h @@ -38,6 +38,7 @@ public: static std::string Pkcs7ToString(PKCS7* p7); static std::string x509CertToString(X509* cert); static std::string SubjectToString(X509* cert); + static bool CheckStringToint(const std::string& in, int& out); }; } // namespace SignatureTools } // namespace OHOS diff --git a/hapsigntool_cpp/utils/src/string_utils.cpp b/hapsigntool_cpp/utils/src/string_utils.cpp index d512422ab683a8d788b37bbcd929f91e871b7345..f7bf48348e7a57849c5cba93e7cc71ae88721e7c 100644 --- a/hapsigntool_cpp/utils/src/string_utils.cpp +++ b/hapsigntool_cpp/utils/src/string_utils.cpp @@ -119,5 +119,14 @@ std::string StringUtils::SubjectToString(X509* cert) OPENSSL_free(subjectStr); return result; } +bool StringUtils::CheckStringToint(const std::string& in, int& out) +{ + std::istringstream iss(in); + if ((iss >> out) && iss.eof()) { + return true; + } + SIGNATURE_TOOLS_LOGE("Cannot convert string:%s to integer", in.c_str()); + return false; +} } // namespace SignatureTools } // namespace OHOS