From b849a6be0898e9f2b5fe19e7331294bdbb296f3c Mon Sep 17 00:00:00 2001 From: li-tiangang4 Date: Tue, 6 Aug 2024 14:43:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-tiangang4 --- common/include/constants_dinput.h | 3 ++- common/include/input_hub.cpp | 14 ++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/common/include/constants_dinput.h b/common/include/constants_dinput.h index 6979e83..d33bffe 100644 --- a/common/include/constants_dinput.h +++ b/common/include/constants_dinput.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -48,6 +48,7 @@ namespace DistributedInput { const uint32_t SCREEN_MSG_MAX = 40 * 1024 * 1024; const uint32_t AUTH_SESSION_SIDE_SERVER = 0; const uint32_t IPC_VECTOR_MAX_SIZE = 32; + const uint32_t EVENT_BUFFER_MAX = 512; /* * Device Type definitions diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index 77ee319..0de2048 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -1071,7 +1071,7 @@ int32_t InputHub::UnregisterFdFromEpoll(int fd) const int32_t InputHub::ReadNotifyLocked() { size_t res; - char eventBuf[512]; + char eventBuf[EVENT_BUFFER_MAX] = {0}; struct inotify_event *event; DHLOGI("readNotify nfd: %{public}d\n", iNotifyFd_); @@ -1088,11 +1088,13 @@ int32_t InputHub::ReadNotifyLocked() size_t eventSize = 0; size_t eventPos = 0; while (res >= sizeof(*event)) { - event = reinterpret_cast(eventBuf + eventPos); - JudgeDeviceOpenOrClose(*event); - eventSize = sizeof(*event) + event->len; - res -= eventSize; - eventPos += eventSize; + if (eventPos < static_cast(EVENT_BUFFER_MAX)) { + event = reinterpret_cast(eventBuf + eventPos); + JudgeDeviceOpenOrClose(*event); + eventSize = sizeof(*event) + event->len; + res -= eventSize; + eventPos += eventSize; + } } } return DH_SUCCESS; -- Gitee