diff --git a/common/include/dinput_errcode.h b/common/include/dinput_errcode.h index bb93ecb25b87f6a0b030e656551300cb8a2077fe..b19237e2f39cd2a27f85248316c8d6ffa0da792c 100644 --- a/common/include/dinput_errcode.h +++ b/common/include/dinput_errcode.h @@ -177,6 +177,9 @@ namespace DistributedInput { constexpr int32_t ERR_DH_INPUT_HIDUMP_INVALID_ARGS = -68000; constexpr int32_t ERR_DH_INPUT_HIDUMP_DUMP_PROCESS_FAIL = -68001; constexpr int32_t ERR_DH_INPUT_HIDUMP_DPRINTF_FAIL = -68002; + + // null pointer is not verified + constexpr int32_t ERR_DH_INPUT_POINTER_NULL = -69000; } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/ipc/src/distributed_input_sink_stub.cpp b/interfaces/ipc/src/distributed_input_sink_stub.cpp index 306f6e4a1ce8fea2eb0f14da0658fe61f3d98ba6..767b7d2a956f6063e4867a0eda336168608a1331 100644 --- a/interfaces/ipc/src/distributed_input_sink_stub.cpp +++ b/interfaces/ipc/src/distributed_input_sink_stub.cpp @@ -139,6 +139,10 @@ int32_t DistributedInputSinkStub::RegisterSharingDhIdListenerInner(MessageParcel MessageOption &option) { sptr listener = iface_cast(data.ReadRemoteObject()); + if (listener == nullptr) { + DHLOGE("RegisterSharingDhIdListenerInner failed, listener is nullptr."); + return ERR_DH_INPUT_POINTER_NULL; + } int32_t ret = RegisterSharingDhIdListener(listener); if (!reply.WriteInt32(ret)) { DHLOGE("RegisterSharingDhIdListenerInner write ret failed, ret = %d", ret); @@ -153,6 +157,10 @@ int32_t DistributedInputSinkStub::RegisterGetSinkScreenInfosInner(MessageParcel { sptr callback = iface_cast(data.ReadRemoteObject()); + if (callback == nullptr) { + DHLOGE("RegisterGetSinkScreenInfosInner failed, callback is nullptr."); + return ERR_DH_INPUT_POINTER_NULL; + } int32_t ret = RegisterGetSinkScreenInfosCallback(callback); if (!reply.WriteInt32(ret)) { DHLOGE("write ret failed, ret = %d", ret); diff --git a/interfaces/ipc/src/distributed_input_source_stub.cpp b/interfaces/ipc/src/distributed_input_source_stub.cpp index 1c7ec802f135ed98e875e9e04b7fdc302096ef76..6475bca19e88865ab3731e8b0f76ca9cc0beee0e 100644 --- a/interfaces/ipc/src/distributed_input_source_stub.cpp +++ b/interfaces/ipc/src/distributed_input_source_stub.cpp @@ -55,9 +55,13 @@ int32_t DistributedInputSourceStub::HandleRegisterDistributedHardware(MessagePar std::string dhId = data.ReadString(); std::string params = data.ReadString(); sptr callback = iface_cast(data.ReadRemoteObject()); + if (callback == nullptr) { + DHLOGE("HandleRegisterDistributedHardware failed, callback is nullptr."); + return ERR_DH_INPUT_POINTER_NULL; + } int32_t ret = RegisterDistributedHardware(devId, dhId, params, callback); if (!reply.WriteInt32(ret)) { - DHLOGE("DistributedInputSourceStub registerDistributedHardware write ret failed"); + DHLOGE("HandleRegisterDistributedHardware write ret failed"); return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; } return DH_SUCCESS; @@ -68,9 +72,13 @@ int32_t DistributedInputSourceStub::HandleUnregisterDistributedHardware(MessageP std::string devId = data.ReadString(); std::string dhId = data.ReadString(); sptr callback = iface_cast(data.ReadRemoteObject()); + if (callback == nullptr) { + DHLOGE("HandleUnregisterDistributedHardware failed, callback is nullptr."); + return ERR_DH_INPUT_POINTER_NULL; + } int32_t ret = UnregisterDistributedHardware(devId, dhId, callback); if (!reply.WriteInt32(ret)) { - DHLOGE("DistributedInputSourceStub unregisterDistributedHardware write ret failed"); + DHLOGE("HandleUnregisterDistributedHardware write ret failed"); return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; } return DH_SUCCESS; @@ -80,6 +88,10 @@ int32_t DistributedInputSourceStub::HandlePrepareRemoteInput(MessageParcel &data { std::string deviceId = data.ReadString(); sptr callback = iface_cast(data.ReadRemoteObject()); + if (callback == nullptr) { + DHLOGE("HandlePrepareRemoteInput failed, callback is nullptr."); + return ERR_DH_INPUT_POINTER_NULL; + } int32_t ret = PrepareRemoteInput(deviceId, callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandlePrepareRemoteInput write ret failed"); @@ -92,6 +104,10 @@ int32_t DistributedInputSourceStub::HandleUnprepareRemoteInput(MessageParcel &da { std::string deviceId = data.ReadString(); sptr callback = iface_cast(data.ReadRemoteObject()); + if (callback == nullptr) { + DHLOGE("HandleUnprepareRemoteInput failed, callback is nullptr."); + return ERR_DH_INPUT_POINTER_NULL; + } int32_t ret = UnprepareRemoteInput(deviceId, callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleUnprepareRemoteInput write ret failed"); @@ -105,9 +121,13 @@ int32_t DistributedInputSourceStub::HandleStartRemoteInput(MessageParcel &data, std::string deviceId = data.ReadString(); uint32_t inputTypes = data.ReadUint32(); sptr callback = iface_cast(data.ReadRemoteObject()); + if (callback == nullptr) { + DHLOGE("HandleStartRemoteInput failed, callback is nullptr."); + return ERR_DH_INPUT_POINTER_NULL; + } int32_t ret = StartRemoteInput(deviceId, inputTypes, callback); if (!reply.WriteInt32(ret)) { - DHLOGE("DistributedInputSourceStub startRemoteInput write ret failed"); + DHLOGE("HandleStartRemoteInput write ret failed"); return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } return DH_SUCCESS; @@ -118,9 +138,13 @@ int32_t DistributedInputSourceStub::HandleStopRemoteInput(MessageParcel &data, M std::string deviceId = data.ReadString(); uint32_t inputTypes = data.ReadUint32(); sptr callback = iface_cast(data.ReadRemoteObject()); + if (callback == nullptr) { + DHLOGE("HandleStopRemoteInput failed, callback is nullptr."); + return ERR_DH_INPUT_POINTER_NULL; + } int32_t ret = StopRemoteInput(deviceId, inputTypes, callback); if (!reply.WriteInt32(ret)) { - DHLOGE("DistributedInputSourceStub stopRemoteInput write ret failed"); + DHLOGE("HandleStopRemoteInput write ret failed"); return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } return DH_SUCCESS; @@ -132,9 +156,13 @@ int32_t DistributedInputSourceStub::HandleStartRelayTypeRemoteInput(MessageParce std::string sinkId = data.ReadString(); uint32_t inputTypes = data.ReadUint32(); sptr callback = iface_cast(data.ReadRemoteObject()); + if (callback == nullptr) { + DHLOGE("HandleStartRelayTypeRemoteInput failed, callback is nullptr."); + return ERR_DH_INPUT_POINTER_NULL; + } int32_t ret = StartRemoteInput(srcId, sinkId, inputTypes, callback); if (!reply.WriteInt32(ret)) { - DHLOGE("DistributedInputSourceStub write ret failed"); + DHLOGE("HandleStartRelayTypeRemoteInput write ret failed"); return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } return DH_SUCCESS; @@ -146,9 +174,13 @@ int32_t DistributedInputSourceStub::HandleStopRelayTypeRemoteInput(MessageParcel std::string sinkId = data.ReadString(); uint32_t inputTypes = data.ReadUint32(); sptr callback = iface_cast(data.ReadRemoteObject()); + if (callback == nullptr) { + DHLOGE("HandleStopRelayTypeRemoteInput failed, callback is nullptr."); + return ERR_DH_INPUT_POINTER_NULL; + } int32_t ret = StopRemoteInput(srcId, sinkId, inputTypes, callback); if (!reply.WriteInt32(ret)) { - DHLOGE("DistributedInputSourceStub write ret failed"); + DHLOGE("HandleStopRelayTypeRemoteInput write ret failed"); return ERR_DH_INPUT_IPC_WRITE_VALID_FAIL; } return DH_SUCCESS; @@ -159,6 +191,10 @@ int32_t DistributedInputSourceStub::HandlePrepareRelayRemoteInput(MessageParcel std::string srcId = data.ReadString(); std::string sinkId = data.ReadString(); sptr callback = iface_cast(data.ReadRemoteObject()); + if (callback == nullptr) { + DHLOGE("HandlePrepareRelayRemoteInput failed, callback is nullptr."); + return ERR_DH_INPUT_POINTER_NULL; + } int32_t ret = PrepareRemoteInput(srcId, sinkId, callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandlePrepareRelayRemoteInput write ret failed"); @@ -172,6 +208,10 @@ int32_t DistributedInputSourceStub::HandleUnprepareRelayRemoteInput(MessageParce std::string srcId = data.ReadString(); std::string sinkId = data.ReadString(); sptr callback = iface_cast(data.ReadRemoteObject()); + if (callback == nullptr) { + DHLOGE("HandleUnprepareRelayRemoteInput failed, callback is nullptr."); + return ERR_DH_INPUT_POINTER_NULL; + } int32_t ret = UnprepareRemoteInput(srcId, sinkId, callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleUnprepareRelayRemoteInput write ret failed"); @@ -201,6 +241,10 @@ int32_t DistributedInputSourceStub::HandleStartDhidRemoteInput(MessageParcel &da } sptr callback = iface_cast(data.ReadRemoteObject()); + if (callback == nullptr) { + DHLOGE("HandleStartDhidRemoteInput failed, callback is nullptr."); + return ERR_DH_INPUT_POINTER_NULL; + } int32_t ret = StartRemoteInput(sinkId, tempVector, callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleStartDhidRemoteInput write ret failed"); @@ -230,6 +274,10 @@ int32_t DistributedInputSourceStub::HandleStopDhidRemoteInput(MessageParcel &dat } sptr callback = iface_cast(data.ReadRemoteObject()); + if (callback == nullptr) { + DHLOGE("HandleStopDhidRemoteInput failed, callback is nullptr."); + return ERR_DH_INPUT_POINTER_NULL; + } int32_t ret = StopRemoteInput(sinkId, tempVector, callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleStopDhidRemoteInput write ret failed"); @@ -260,6 +308,10 @@ int32_t DistributedInputSourceStub::HandleStartRelayDhidRemoteInput(MessageParce } sptr callback = iface_cast(data.ReadRemoteObject()); + if (callback == nullptr) { + DHLOGE("HandleStartRelayDhidRemoteInput failed, callback is nullptr."); + return ERR_DH_INPUT_POINTER_NULL; + } int32_t ret = StartRemoteInput(srcId, sinkId, tempVector, callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleStartRelayDhidRemoteInput write ret failed"); @@ -290,6 +342,10 @@ int32_t DistributedInputSourceStub::HandleStopRelayDhidRemoteInput(MessageParcel } sptr callback = iface_cast(data.ReadRemoteObject()); + if (callback == nullptr) { + DHLOGE("HandleStopRelayDhidRemoteInput failed, callback is nullptr."); + return ERR_DH_INPUT_POINTER_NULL; + } int32_t ret = StopRemoteInput(srcId, sinkId, tempVector, callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleStopRelayDhidRemoteInput write ret failed"); @@ -315,6 +371,10 @@ int32_t DistributedInputSourceStub::HandleSyncNodeInfoRemoteInput(MessageParcel int32_t DistributedInputSourceStub::HandleRegisterAddWhiteListCallback(MessageParcel &data, MessageParcel &reply) { sptr callback = iface_cast(data.ReadRemoteObject()); + if (callback == nullptr) { + DHLOGE("HandleRegisterAddWhiteListCallback failed, callback is nullptr."); + return ERR_DH_INPUT_POINTER_NULL; + } int32_t ret = RegisterAddWhiteListCallback(callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleRegisterAddWhiteListCallback write ret failed"); @@ -327,9 +387,9 @@ int32_t DistributedInputSourceStub::HandleRegisterDelWhiteListCallback(MessagePa { sptr callback = iface_cast(data.ReadRemoteObject()); if (callback == nullptr) { - DHLOGI("HandleRegisterDelWhiteListCallback callback is null"); + DHLOGE("HandleRegisterDelWhiteListCallback failed, callback is nullptr."); + return ERR_DH_INPUT_POINTER_NULL; } - int32_t ret = RegisterDelWhiteListCallback(callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleRegisterDelWhiteListCallback write ret failed"); @@ -341,6 +401,10 @@ int32_t DistributedInputSourceStub::HandleRegisterDelWhiteListCallback(MessagePa int32_t DistributedInputSourceStub::HandleRegisterInputNodeListener(MessageParcel &data, MessageParcel &reply) { sptr callback = iface_cast(data.ReadRemoteObject()); + if (callback == nullptr) { + DHLOGE("HandleRegisterInputNodeListener failed, callback is nullptr."); + return ERR_DH_INPUT_POINTER_NULL; + } int32_t ret = RegisterInputNodeListener(callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleRegisterInputNodeListener write ret failed"); @@ -353,6 +417,10 @@ int32_t DistributedInputSourceStub::HandleRegisterInputNodeListener(MessageParce int32_t DistributedInputSourceStub::HandleUnRegisterInputNodeListener(MessageParcel &data, MessageParcel &reply) { sptr callback = iface_cast(data.ReadRemoteObject()); + if (callback == nullptr) { + DHLOGE("HandleUnRegisterInputNodeListener failed, callback is nullptr."); + return ERR_DH_INPUT_POINTER_NULL; + } int32_t ret = RegisterInputNodeListener(callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleUnRegisterInputNodeListener write ret failed"); @@ -365,6 +433,10 @@ int32_t DistributedInputSourceStub::HandleUnRegisterInputNodeListener(MessagePar int32_t DistributedInputSourceStub::HandleRegisterSimulationEventListener(MessageParcel &data, MessageParcel &reply) { sptr callback = iface_cast(data.ReadRemoteObject()); + if (callback == nullptr) { + DHLOGE("HandleRegisterSimulationEventListener failed, callback is nullptr."); + return ERR_DH_INPUT_POINTER_NULL; + } int32_t ret = RegisterSimulationEventListener(callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleRegisterSimulationEventListener write ret failed, ret = %d", ret); @@ -377,6 +449,10 @@ int32_t DistributedInputSourceStub::HandleRegisterSimulationEventListener(Messag int32_t DistributedInputSourceStub::HandleUnregisterSimulationEventListener(MessageParcel &data, MessageParcel &reply) { sptr callback = iface_cast(data.ReadRemoteObject()); + if (callback == nullptr) { + DHLOGE("HandleUnregisterSimulationEventListener failed, callback is nullptr."); + return ERR_DH_INPUT_POINTER_NULL; + } int32_t ret = UnregisterSimulationEventListener(callback); if (!reply.WriteInt32(ret)) { DHLOGE("HandleUnregisterSimulationEventListener write ret failed, ret = %d", ret);