diff --git a/hapsigntool_cpp/api/include/service_api.h b/hapsigntool_cpp/api/include/service_api.h index 968df287baec4243debdd77685da4c4383d2a455..11f5a88993c5a58c07a6bbcb14f04bfb4ab01f09 100644 --- a/hapsigntool_cpp/api/include/service_api.h +++ b/hapsigntool_cpp/api/include/service_api.h @@ -24,7 +24,7 @@ namespace SignatureTools { class ServiceApi { public: ServiceApi() = default; - ~ServiceApi() = default; + virtual ~ServiceApi() = default; virtual bool GenerateKeyStore(Options* params) = 0; virtual bool GenerateCsr(Options* params) = 0; diff --git a/hapsigntool_cpp/api/src/cert_tools.cpp b/hapsigntool_cpp/api/src/cert_tools.cpp index e634a2e15fd0d97b8d381e37466f64ef2a13b295..7f245c2cf8f2c0de36376ccdff4f36f9e471ea9d 100644 --- a/hapsigntool_cpp/api/src/cert_tools.cpp +++ b/hapsigntool_cpp/api/src/cert_tools.cpp @@ -361,7 +361,7 @@ bool CertTools::SetKeyUsage(X509* cert, Options* options) } } else { bool keyUsageCritical = options->GetBool(Options::KEY_USAGE_CRITICAL); - int crit = keyUsageCritical > 0 ? 1 : 0; + int crit = keyUsageCritical ? 1 : 0; std::vector vecs = StringUtils::SplitString(keyUsage.c_str(), ','); key = std::accumulate(vecs.begin(), vecs.end(), key, [&](long key, const std::string& vec) { return key | externDic[vec]; }); diff --git a/hapsigntool_cpp/hap/entity/src/sign_content_info.cpp b/hapsigntool_cpp/hap/entity/src/sign_content_info.cpp index 1ef57cf0dcb462029e31a0f5721ab8c0ce020bd3..de1c6b9aeef2f61622c1239ac03767ec601800f1 100644 --- a/hapsigntool_cpp/hap/entity/src/sign_content_info.cpp +++ b/hapsigntool_cpp/hap/entity/src/sign_content_info.cpp @@ -76,12 +76,32 @@ std::vector SignContentInfo::GetByteContent() } for (const auto& tmp : m_hashData) { + if (index >= ret.size()) { + PrintErrorNumberMsg("SIGN_ERROR", SIGN_ERROR, "InsertShortToByteArray failed."); + return std::vector(); + } ret[index] = tmp.m_type; index++; + + if (index >= ret.size()) { + PrintErrorNumberMsg("SIGN_ERROR", SIGN_ERROR, "InsertShortToByteArray failed."); + return std::vector(); + } ret[index] = tmp.m_tag; index++; + index = ByteArrayUtils::InsertShortToByteArray(ret, ret.size(), index, tmp.m_algId); + if (index < 0) { + PrintErrorNumberMsg("SIGN_ERROR", SIGN_ERROR, "InsertShortToByteArray failed."); + return std::vector(); + } + index = ByteArrayUtils::InsertIntToByteArray(ret, index, tmp.m_length); + if (index < 0) { + PrintErrorNumberMsg("SIGN_ERROR", SIGN_ERROR, "InsertShortToByteArray failed."); + return std::vector(); + } + index = ByteArrayUtils::InsertByteToByteArray(ret, index, tmp.m_hash, tmp.m_hash.size()); if (index < 0) { PrintErrorNumberMsg("SIGN_ERROR", SIGN_ERROR, "InsertShortToByteArray failed."); diff --git a/hapsigntool_cpp/utils/src/string_utils.cpp b/hapsigntool_cpp/utils/src/string_utils.cpp index 662065d7e6b3407e2c3f9011caedf3c4c3770a1a..b5ccd7c8792af8c0afb7c3f156c583f21607ed02 100644 --- a/hapsigntool_cpp/utils/src/string_utils.cpp +++ b/hapsigntool_cpp/utils/src/string_utils.cpp @@ -62,7 +62,7 @@ std::string StringUtils::FormatLoading(std::string& dealStr) char comma = ','; char slash = '/'; std::string del = dealStr.substr(dealStr.find_first_of("/") + 1, dealStr.size()); - int position = 0; + std::string::size_type position = 0; while ((position = del.find(slash, position)) != std::string::npos) { del.insert(position + 1, " "); position++;