diff --git a/common/include/constants_dinput.h b/common/include/constants_dinput.h index 6979e8358adf37b3f8bb08086ede5063eb63333a..d33bffea0f14374b61b4453f53f977f974411d7f 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 77ee319bbd58df04ad677f5b87e0a78336bcce95..55704f92fee64e95fc9a025cb5b995beddd96c24 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_); @@ -1087,7 +1087,7 @@ int32_t InputHub::ReadNotifyLocked() { size_t eventSize = 0; size_t eventPos = 0; - while (res >= sizeof(*event)) { + while (res >= sizeof(*event) && eventPos < static_cast(EVENT_BUFFER_MAX)) { event = reinterpret_cast(eventBuf + eventPos); JudgeDeviceOpenOrClose(*event); eventSize = sizeof(*event) + event->len;