From 9ebaf3ca017442d117a8d3ba5296065cb7343d4a Mon Sep 17 00:00:00 2001 From: zhanzeyi Date: Sat, 13 Jul 2024 14:25:11 +0800 Subject: [PATCH 1/3] fix build bug Signed-off-by: zhanzeyi --- hapsigntool_cpp/codesigning/fsverity/include/thread_pool.h | 3 --- hapsigntool_cpp/common/src/byte_buffer.cpp | 3 ++- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/hapsigntool_cpp/codesigning/fsverity/include/thread_pool.h b/hapsigntool_cpp/codesigning/fsverity/include/thread_pool.h index a995bf8d..9c9684a9 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 5f7dabf5..447b210b 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"); -- Gitee From de7c89d91a867696fafae27691512143130a0265 Mon Sep 17 00:00:00 2001 From: zhanzeyi Date: Sat, 13 Jul 2024 15:49:01 +0800 Subject: [PATCH 2/3] fix try catch Signed-off-by: zhanzeyi --- hapsigntool_cpp/cmd/src/cmd_util.cpp | 11 +++-------- hapsigntool_cpp/utils/include/string_utils.h | 1 + hapsigntool_cpp/utils/src/string_utils.cpp | 9 +++++++++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/hapsigntool_cpp/cmd/src/cmd_util.cpp b/hapsigntool_cpp/cmd/src/cmd_util.cpp index e17b973f..fbb4b2b1 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,8 @@ 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/utils/include/string_utils.h b/hapsigntool_cpp/utils/include/string_utils.h index ab8a253b..44122ee3 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 d512422a..f7bf4834 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 -- Gitee From 9337ec3257b83275e683d5df7412d40b7c170018 Mon Sep 17 00:00:00 2001 From: zhanzeyi Date: Sat, 13 Jul 2024 18:05:56 +0800 Subject: [PATCH 3/3] fix code check Signed-off-by: zhanzeyi --- hapsigntool_cpp/cmd/src/cmd_util.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/hapsigntool_cpp/cmd/src/cmd_util.cpp b/hapsigntool_cpp/cmd/src/cmd_util.cpp index fbb4b2b1..1d87240d 100644 --- a/hapsigntool_cpp/cmd/src/cmd_util.cpp +++ b/hapsigntool_cpp/cmd/src/cmd_util.cpp @@ -89,7 +89,6 @@ 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); - if (!StringUtils::CheckStringToint(val, basicConstraintsPathLen)) { PrintErrorNumberMsg("COMMAND_PARAM_ERROR", COMMAND_PARAM_ERROR, "Invalid parameter '" + val + "', You should fill in the numbers"); -- Gitee