From c7a23e315b86ad614678e0d427e751407a11726e Mon Sep 17 00:00:00 2001 From: wangyikai Date: Fri, 8 Nov 2024 14:57:25 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90hdf=5Fcore=E3=80=91stoi=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=E6=9C=89=E6=95=88=E6=80=A7=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyikai --- adapter/uhdf2/hdi/src/hdi_support.cpp | 14 ++++++++++++-- adapter/uhdf2/hdi/test/smq_test/smq_test.cpp | 7 +++++++ framework/support/posix/src/osal_mem.c | 12 ++++++++++-- framework/tools/hdi-gen/parser/parser.cpp | 17 +++++++++++++---- 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/adapter/uhdf2/hdi/src/hdi_support.cpp b/adapter/uhdf2/hdi/src/hdi_support.cpp index 8ed562e3e..2938711b8 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 1fed1af9b..3fa594328 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 11fb21f0a..147d384a4 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 a03d2d0b5..5b2e34a5d 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; } -- Gitee