diff --git a/adapter/uhdf2/hdi/src/hdi_support.cpp b/adapter/uhdf2/hdi/src/hdi_support.cpp index 8ed562e3e59c960f496490a5d5fc0dd84effa59b..2938711b8c1ae62fb81c05ee06d466bc32343082 100644 --- a/adapter/uhdf2/hdi/src/hdi_support.cpp +++ b/adapter/uhdf2/hdi/src/hdi_support.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include #include "hdi_support.h" #include #include @@ -106,8 +107,17 @@ static int32_t ParseInterface( return HDF_FAILURE; } - uint32_t versionMajor = std::stoul(result[INTERFACE_VERSION_MAJOR_INDEX]); - uint32_t versionMinor = std::stoul(result[INTERFACE_VERSION_MINOR_INDEX]); + const auto &majorVersion = result[INTERFACE_VERSION_MAJOR_INDEX].str(); + const auto &minorVersion = result[INTERFACE_VERSION_MINOR_INDEX].str(); + + bool isNumeric = std::all_of(majorVersion.begin(), majorVersion.end(), ::isdigit); + isNumeric = isNumeric && std::all_of(minorVersion.begin(), minorVersion.end(), ::isdigit); + if (!isNumeric) { + return HDF_FAILURE; + } + + uint32_t versionMajor = std::stoul(majorVersion); + uint32_t versionMinor = std::stoul(minorVersion); std::string interfaceName = result[INTERFACE_NAME_INDEX]; interface = interfaceName[0] == 'I' ? interfaceName.substr(1) : interfaceName; diff --git a/adapter/uhdf2/hdi/test/smq_test/smq_test.cpp b/adapter/uhdf2/hdi/test/smq_test/smq_test.cpp index 1fed1af9b5699882185d284c1af41f934544e83e..3fa594328125eaecc833c7bba8d4761ac01cbac7 100644 --- a/adapter/uhdf2/hdi/test/smq_test/smq_test.cpp +++ b/adapter/uhdf2/hdi/test/smq_test/smq_test.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include #include #include #include @@ -110,6 +111,9 @@ static bool QueryPidOfHostName(const std::string &hostName, int &hostPid) return false; } + if (!std::all_of(resBuf.begin(), resBuf.end(), ::isdigit)) { + return false; + } hostPid = std::stoi(resBuf); return true; } @@ -138,6 +142,9 @@ static bool QueryOpendFdsByHostPid(int hostPid, std::set &fds) std::vector fdsResult = Split(resBuf, " "); for (const auto &fdStr : fdsResult) { + if (!std::all_of(fdStr.begin(), fdStr.end(), ::isdigit)) { + continue; + } int fd = std::stoi(fdStr); if (fd == resFd) { continue; diff --git a/framework/support/posix/src/osal_mem.c b/framework/support/posix/src/osal_mem.c index 11fb21f0a041f6e11b38f2e5e0fccd4da3278fbb..147d384a4b96bc438a194574793ca34a9927cf9a 100644 --- a/framework/support/posix/src/osal_mem.c +++ b/framework/support/posix/src/osal_mem.c @@ -18,12 +18,16 @@ void *OsalMemAlloc(size_t size) void *buf = NULL; if (size == 0) { +// LCOV_EXCL_START HDF_LOGE("%s invalid param", __func__); return NULL; +// LCOV_EXCL_STOP } if (size > SIZE_MAX) { +// LCOV_EXCL_START HDF_LOGE("%s invalid param : size", __func__); return NULL; +// LCOV_EXCL_STOP } buf = malloc(size); @@ -36,12 +40,16 @@ void *OsalMemCalloc(size_t size) void *buf = NULL; if (size == 0) { +// LCOV_EXCL_START HDF_LOGE("%s invalid param", __func__); return NULL; +// LCOV_EXCL_STOP } if (size > SIZE_MAX) { +// LCOV_EXCL_START HDF_LOGE("%s invalid param : size", __func__); return NULL; +// LCOV_EXCL_STOP } buf = OsalMemAlloc(size); @@ -51,7 +59,7 @@ void *OsalMemCalloc(size_t size) return buf; } - +// LCOV_EXCL_START void *OsalMemAllocAlign(size_t alignment, size_t size) { void *buf = NULL; @@ -70,7 +78,7 @@ void *OsalMemAllocAlign(size_t alignment, size_t size) return buf; } - +// LCOV_EXCL_STOP void OsalMemFree(void *mem) { if (mem != NULL) { diff --git a/framework/tools/hdi-gen/parser/parser.cpp b/framework/tools/hdi-gen/parser/parser.cpp index a03d2d0b53ca22e94d6609f229b6e8937522ab9f..5b2e34a5d2188d0056d4d99005486fa2d9fb1fe6 100644 --- a/framework/tools/hdi-gen/parser/parser.cpp +++ b/framework/tools/hdi-gen/parser/parser.cpp @@ -7,9 +7,8 @@ */ #include "parser/parser.h" - +#include #include - #include "ast/ast_array_type.h" #include "ast/ast_enum_type.h" #include "ast/ast_map_type.h" @@ -177,8 +176,18 @@ bool Parser::ParserPackageInfo(const std::string &packageName) } ast_->SetPackageName(result.str(RE_PACKAGE_INDEX).c_str()); - size_t majorVersion = std::stoul(result.str(RE_PACKAGE_MAJOR_VER_INDEX)); - size_t minorVersion = std::stoul(result.str(RE_PACKAGE_MINOR_VER_INDEX)); + + const auto majorVersionStr = result.str(RE_PACKAGE_MAJOR_VER_INDEX); + const auto minorVersionStr = result.str(RE_PACKAGE_MINOR_VER_INDEX); + + bool isNumeric = std::all_of(majorVersionStr.begin(), majorVersionStr.end(), ::isdigit); + isNumeric = isNumeric && std::all_of(minorVersionStr.begin(), minorVersionStr.end(), ::isdigit); + if (!isNumeric) { + return false; + } + + size_t majorVersion = std::stoul(majorVersionStr); + size_t minorVersion = std::stoul(minorVersionStr); ast_->SetVersion(majorVersion, minorVersion); return true; }