From 0ef9dd8644d6ddea66885ee6430f137dd800c7ff Mon Sep 17 00:00:00 2001 From: huyx Date: Fri, 2 Aug 2024 14:33:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- adapter/uhdf2/manager/src/devmgr_uevent.c | 4 ++++ framework/support/posix/src/osal_time.c | 3 ++- framework/utils/src/hdf_map.c | 2 +- interfaces/inner_api/hdi/base/hdi_smq.h | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/adapter/uhdf2/manager/src/devmgr_uevent.c b/adapter/uhdf2/manager/src/devmgr_uevent.c index b69fc0a25..47dbcca04 100644 --- a/adapter/uhdf2/manager/src/devmgr_uevent.c +++ b/adapter/uhdf2/manager/src/devmgr_uevent.c @@ -113,6 +113,10 @@ static void DevMgrUeventReplaceLineFeed(char *str, const char *subStr, char c) while ((ptr = strstr(str, subStr)) != NULL) { ptr[0] = c; uint32_t i = 1; + if (strlen(ptr) < 1 || strlen(ptr) > SIZE_MAX) { + HDF_LOGE("strlen(ptr) overflows"); + return; + } const size_t len = strlen(ptr) - 1; for (; i < len; i++) { ptr[i] = ptr[i + 1]; diff --git a/framework/support/posix/src/osal_time.c b/framework/support/posix/src/osal_time.c index 149234cae..67c386a1e 100644 --- a/framework/support/posix/src/osal_time.c +++ b/framework/support/posix/src/osal_time.c @@ -51,7 +51,8 @@ int32_t OsalDiffTime(const OsalTimespec *start, const OsalTimespec *end, OsalTim usec = (HDF_KILO_UNIT * HDF_KILO_UNIT); sec = 1; } - if (end->sec - start->sec > UINT64_MAX - sec) { + + if (end->sec - start->sec - sec < 0 || end->sec > UINT64_MAX - sec - start->sec) { HDF_LOGE("%s end time invalid", __func__); return HDF_ERR_INVALID_PARAM; } diff --git a/framework/utils/src/hdf_map.c b/framework/utils/src/hdf_map.c index 31df0b906..6a11063f6 100644 --- a/framework/utils/src/hdf_map.c +++ b/framework/utils/src/hdf_map.c @@ -45,7 +45,7 @@ static uint32_t MapHash(const char *hashKey) static uint32_t MapHashIdx(const Map *map, uint32_t hash) { - if (map->bucketSize > HDF_UINT32_MAX) { + if (map->bucketSize < 1 || map->bucketSize > HDF_UINT32_MAX) { return 0; } return (hash & (map->bucketSize - 1)); diff --git a/interfaces/inner_api/hdi/base/hdi_smq.h b/interfaces/inner_api/hdi/base/hdi_smq.h index 73ff7c7f7..ecdc37ee7 100644 --- a/interfaces/inner_api/hdi/base/hdi_smq.h +++ b/interfaces/inner_api/hdi/base/hdi_smq.h @@ -401,7 +401,7 @@ bool SharedMemQueue::IsGood() template size_t SharedMemQueue::Align(size_t num, size_t alignSize) { - if ((num + alignSize - 1) < 0 || num > (SIZE_MAX - alignSize)) { + if ((num + alignSize) < 1 || num > (SIZE_MAX - alignSize) || alignSize > (SIZE_MAX - num)) { HDF_LOGE("Invalid parameter num or alignSize"); return 0; } -- Gitee