diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index f6190e4998a4eeb6dea7f71b504ac7251172595c..fb803de39dcf307dcfd9ba2e4f5e0219ce431078 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -302,6 +302,9 @@ void InputHub::RecordDeviceChangeStates(Device *device, struct input_event readB size_t InputHub::CollectEvent(RawEvent *buffer, size_t &capacity, Device *device, struct input_event readBuffer[], const size_t count) { + if (capacity < 1) { + return 0; + } std::vector needFilted(capacity, false); bool isTouchEvent = false; if ((device->classes & INPUT_DEVICE_CLASS_TOUCH_MT) || (device->classes & INPUT_DEVICE_CLASS_TOUCH)) { @@ -915,8 +918,8 @@ int32_t InputHub::QueryLocalTouchScreenInfo(int fd, std::unique_ptr &dev std::string InputHub::StringPrintf(const char *format, ...) const { - static const int kSpaceLength = 1024; - char space[kSpaceLength]; + static const int spaceLength = 1024; + char space[spaceLength] = {0}; va_list ap; va_start(ap, format); diff --git a/interfaces/ipc/src/distributed_input_sink_stub.cpp b/interfaces/ipc/src/distributed_input_sink_stub.cpp index dfc0694101e3833387609f354c238df0469aad49..32789b508db1b3e2d1ff4afea93f013428c10c30 100644 --- a/interfaces/ipc/src/distributed_input_sink_stub.cpp +++ b/interfaces/ipc/src/distributed_input_sink_stub.cpp @@ -123,8 +123,8 @@ int32_t DistributedInputSinkStub::NotifyStartDScreenInner(MessageParcel &data, M GetAnonyString(sourcePhyId).c_str(), sourcePhyFd, sourcePhyWidth, sourcePhyHeight); SrcScreenInfo srcScreenInfo = { .devId = devId, - .sessionId = sessionId, .uuid = uuid, + .sessionId = sessionId, .sourceWinId = sourceWinId, .sourceWinWidth = sourceWinWidth, .sourceWinHeight = sourceWinHeight, diff --git a/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.cpp b/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.cpp index 6ffb823f56b58c64d2963ca7ec4c038403a19fd8..471114a07bbfc6f0be1e44e3a95aaadb3f427e55 100644 --- a/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.cpp +++ b/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -24,16 +24,22 @@ namespace OHOS { namespace DistributedHardware { namespace DistributedInput { +namespace { + const int32_t PERMISSION_ENABLE_INDEX = 0; + const int32_t PERMISSION_DATASYNC_INDEX = 1; + const int32_t PERMISSION_ACCESS_INDEX = 2; + const int32_t PERMISSION_NUMS = 3; +} void AddWhiteListInfosCallbackTest::SetUp() { uint64_t tokenId; - const char *perms[3]; - perms[0] = "ohos.permission.ENABLE_DISTRIBUTED_HARDWARE"; - perms[1] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC; - perms[2] = "ohos.permission.ACCESS_DISTRIBUTED_HARDWARE"; + const char *perms[PERMISSION_NUMS]; + perms[PERMISSION_ENABLE_INDEX] = "ohos.permission.ENABLE_DISTRIBUTED_HARDWARE"; + perms[PERMISSION_DATASYNC_INDEX] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC; + perms[PERMISSION_ACCESS_INDEX] = "ohos.permission.ACCESS_DISTRIBUTED_HARDWARE"; NativeTokenInfoParams infoInstance = { .dcapsNum = 0, - .permsNum = 3, + .permsNum = PERMISSION_NUMS, .aclsNum = 0, .dcaps = NULL, .perms = perms, diff --git a/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.cpp b/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.cpp index dfb97c88609fcbf21f4c4956842520362a55b9ae..ad70fccac25d689bd0ae1e988ec379bf254fde30 100644 --- a/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.cpp +++ b/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -27,16 +27,22 @@ namespace OHOS { namespace DistributedHardware { namespace DistributedInput { +namespace { + const int32_t PERMISSION_ENABLE_INDEX = 0; + const int32_t PERMISSION_DATASYNC_INDEX = 1; + const int32_t PERMISSION_ACCESS_INDEX = 2; + const int32_t PERMISSION_NUMS = 3; +} void DInputSourceCallBackTest::SetUp() { uint64_t tokenId; - const char *perms[3]; - perms[0] = "ohos.permission.ENABLE_DISTRIBUTED_HARDWARE"; - perms[1] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC; - perms[2] = "ohos.permission.ACCESS_DISTRIBUTED_HARDWARE"; + const char *perms[PERMISSION_NUMS]; + perms[PERMISSION_ENABLE_INDEX] = "ohos.permission.ENABLE_DISTRIBUTED_HARDWARE"; + perms[PERMISSION_DATASYNC_INDEX] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC; + perms[PERMISSION_ACCESS_INDEX] = "ohos.permission.ACCESS_DISTRIBUTED_HARDWARE"; NativeTokenInfoParams infoInstance = { .dcapsNum = 0, - .permsNum = 3, + .permsNum = PERMISSION_NUMS, .aclsNum = 0, .dcaps = NULL, .perms = perms, diff --git a/services/sink/sinkmanager/test/sinkmanagerunittest/mock/mock_process.cpp b/services/sink/sinkmanager/test/sinkmanagerunittest/mock/mock_process.cpp index 05c4750510a32f6d56bb8535bddbcec7bfb55a72..e5796b31aa82072091ba5cafa366c6a9bf264de5 100644 --- a/services/sink/sinkmanager/test/sinkmanagerunittest/mock/mock_process.cpp +++ b/services/sink/sinkmanager/test/sinkmanagerunittest/mock/mock_process.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -23,7 +23,7 @@ namespace DistributedHardware { namespace DistributedInput { void MockProcess::MockDinputProcess(const char* processName) { - static const char *PERMS[] = { + static const char *perms[] = { "ohos.permission.DISTRIBUTED_DATASYNC" }; uint64_t tokenId; @@ -32,7 +32,7 @@ void MockProcess::MockDinputProcess(const char* processName) .permsNum = 1, .aclsNum = 0, .dcaps = nullptr, - .perms = PERMS, + .perms = perms, .acls = nullptr, .processName = processName, .aplStr = "system_core", diff --git a/services/sink/transport/src/distributed_input_sink_transport.cpp b/services/sink/transport/src/distributed_input_sink_transport.cpp index f1f2dfd230dd16c85aa80d682658f3f30db212ad..b755822a2dbcd6d0cbfc83a83325b430317c6780 100644 --- a/services/sink/transport/src/distributed_input_sink_transport.cpp +++ b/services/sink/transport/src/distributed_input_sink_transport.cpp @@ -253,7 +253,7 @@ void DistributedInputSinkTransport::SendKeyStateNodeMsgBatch(const int32_t sessi void DistributedInputSinkTransport::DoSendMsgBatch(const int32_t sessionId, const std::vector &events) { - int64_t currentTimeNs = GetCurrentTimeUs() * 1000LL; + int64_t currentTimeNs = static_cast(GetCurrentTimeUs()) * 1000LL; std::shared_ptr eventsJsonArr = std::make_shared(); for (const auto &ev : events) { nlohmann::json tmpJson; @@ -582,6 +582,12 @@ void DistributedInputSinkTransport::DInputSinkEventHandler::RecordEventLog( { for (nlohmann::json::const_iterator iter = events->cbegin(); iter != events->cend(); ++iter) { nlohmann::json event = *iter; + if (!IsInt32(event, INPUT_KEY_TYPE) || !IsInt64(event, INPUT_KEY_WHEN) || + !IsUInt32(event, INPUT_KEY_CODE) || !IsInt32(event, INPUT_KEY_VALUE) || + !IsString(event, INPUT_KEY_PATH)) { + DHLOGE("The key is invaild."); + continue; + } std::string eventType = ""; int32_t evType = event[INPUT_KEY_TYPE]; switch (evType) { diff --git a/services/source/inputinject/src/virtual_device.cpp b/services/source/inputinject/src/virtual_device.cpp index ecd2636dd0a57907d3cb5cf9e741f1b9b5ca5b58..aa5dd6e29e8567b01d78c71882f2d7e31bb53446 100644 --- a/services/source/inputinject/src/virtual_device.cpp +++ b/services/source/inputinject/src/virtual_device.cpp @@ -92,7 +92,7 @@ bool VirtualDevice::CreateKey(const InputDevice &inputDevice) void VirtualDevice::SetABSInfo(struct uinput_user_dev &inputUserDev, const InputDevice &inputDevice) { DHLOGI("SetABSInfo!"); - for (const auto item : inputDevice.absInfos) { + for (auto item : inputDevice.absInfos) { int absCode = item.first; std::vector absInfo = item.second; DHLOGI("SetABSInfo nodeName: %{public}s, absCode: %{public}d, absMin: %{public}d, absMax: %{public}d, " diff --git a/utils/src/dinput_utils_tool.cpp b/utils/src/dinput_utils_tool.cpp index 06e3dc6b6222923b2555a68157bf6c384e88fac1..80a318778ac9f495ba6b7f661706b2ee1f80d888 100644 --- a/utils/src/dinput_utils_tool.cpp +++ b/utils/src/dinput_utils_tool.cpp @@ -127,7 +127,9 @@ std::string SetAnonyId(const std::string &message) dhidStr = dhidStr.substr(pos + 1, dhidStr.size()); pos = dhidStr.find("."); } - jsonObj[DINPUT_SOFTBUS_KEY_VECTOR_DHID] = anonyDhidStr.substr(0, anonyDhidStr.length() - 1); + if (anonyDhidStr.length() >= 1) { + jsonObj[DINPUT_SOFTBUS_KEY_VECTOR_DHID] = anonyDhidStr.substr(0, anonyDhidStr.length() - 1); + } } if (IsString(jsonObj, DINPUT_SOFTBUS_KEY_SRC_DEV_ID)) { jsonObj[DINPUT_SOFTBUS_KEY_SRC_DEV_ID] = GetAnonyString(jsonObj[DINPUT_SOFTBUS_KEY_SRC_DEV_ID]); @@ -232,6 +234,10 @@ std::string GetAnonyInt32(const int32_t value) return nullString; } size_t length = strlen(tempBuffer); + if (length < 1) { + DHLOGE("tempBuffer length error."); + return ""; + } for (size_t i = 1; i <= length - 1; i++) { tempBuffer[i] = '*'; } @@ -430,6 +436,10 @@ void ResetVirtualDevicePressedKeys(const std::vector &nodePaths) std::string GetString(const std::vector &vec) { std::string retStr = "["; + if (vec.size() < 1) { + DHLOGE("vec size error."); + return ""; + } for (uint32_t i = 0; i < vec.size(); i++) { if (i != (vec.size() - 1)) { retStr += vec[i] + ", ";