diff --git a/services/miscdevice_service/src/miscdevice_service_stub.cpp b/services/miscdevice_service/src/miscdevice_service_stub.cpp index 9c612a592b59d65e0072c3ebb3b1256677c700e0..528befc545d5654ade843c8bd31a7926e36318d2 100644 --- a/services/miscdevice_service/src/miscdevice_service_stub.cpp +++ b/services/miscdevice_service/src/miscdevice_service_stub.cpp @@ -62,15 +62,24 @@ MiscdeviceServiceStub::~MiscdeviceServiceStub() int32_t MiscdeviceServiceStub::IsAbilityAvailablePb(MessageParcel &data, MessageParcel &reply) { - MiscdeviceDeviceId groupId = static_cast(data.ReadUint32()); + uint32_t groupID; + if (!data.ReadUint32(groupID)) { + MISC_HILOGE("Parcel read failed"); + return ERROR; + } + MiscdeviceDeviceId groupId = static_cast(groupID); reply.WriteBool(IsAbilityAvailable(groupId)); return NO_ERROR; } int32_t MiscdeviceServiceStub::IsVibratorEffectAvailablePb(MessageParcel &data, MessageParcel &reply) { - int32_t vibratorId = data.ReadInt32(); - std::string effectType = data.ReadString(); + int32_t vibratorId; + std::string effectType; + if ((!data.ReadInt32(vibratorId)) || (!data.ReadString(effectType))) { + MISC_HILOGE("Parcel read failed"); + return ERROR; + } reply.WriteBool(IsVibratorEffectAvailable(vibratorId, effectType)); return NO_ERROR; } @@ -113,7 +122,11 @@ int32_t MiscdeviceServiceStub::CancelVibratorPb(MessageParcel &data, MessageParc MISC_HILOGE("result: %{public}d", ret); return PERMISSION_DENIED; } - int32_t vibratorId = data.ReadInt32(); + int32_t vibratorId; + if (!data.ReadInt32(vibratorId)) { + MISC_HILOGE("Parcel read failed"); + return ERROR; + } return CancelVibrator(vibratorId); } @@ -149,12 +162,15 @@ int32_t MiscdeviceServiceStub::PlayCustomVibratorEffectPb(MessageParcel &data, M MISC_HILOGE("result: %{public}d", ret); return PERMISSION_DENIED; } - int32_t vibratorId = data.ReadInt32(); + int32_t vibratorId; std::vector timing; - data.ReadInt32Vector(&timing); std::vector intensity; - data.ReadInt32Vector(&intensity); - int32_t periodCount = data.ReadInt32(); + int32_t periodCount; + if ((!data.ReadInt32(vibratorId)) || (!data.ReadInt32Vector(&timing)) || + (!data.ReadInt32Vector(&intensity)) || (!data.ReadInt32(periodCount))) { + MISC_HILOGE("Parcel read failed"); + return ERROR; + } return PlayCustomVibratorEffect(vibratorId, timing, intensity, periodCount); } @@ -168,8 +184,12 @@ int32_t MiscdeviceServiceStub::StopVibratorEffectPb(MessageParcel &data, Message MISC_HILOGE("result: %{public}d", ret); return PERMISSION_DENIED; } - int32_t vibratorId = data.ReadInt32(); - std::string effectType = data.ReadString(); + int32_t vibratorId; + std::string effectType; + if ((!data.ReadInt32(vibratorId)) || (!data.ReadString(effectType))) { + MISC_HILOGE("Parcel read failed"); + return ERROR; + } return StopVibratorEffect(vibratorId, effectType); } @@ -183,15 +203,23 @@ int32_t MiscdeviceServiceStub::SetVibratorParameterPb(MessageParcel &data, Messa MISC_HILOGE("result: %{public}d", ret); return PERMISSION_DENIED; } - int32_t vibratorId = data.ReadInt32(); - std::string cmd = data.ReadString(); + int32_t vibratorId; + std::string cmd; + if ((!data.ReadInt32(vibratorId)) || (!data.ReadString(cmd))) { + MISC_HILOGE("Parcel read failed"); + return ERROR; + } return SetVibratorParameter(vibratorId, cmd); } int32_t MiscdeviceServiceStub::GetVibratorParameterPb(MessageParcel &data, MessageParcel &reply) { - int32_t vibratorId = data.ReadInt32(); - std::string cmd = data.ReadString(); + int32_t vibratorId; + std::string cmd; + if ((!data.ReadInt32(vibratorId)) || (!data.ReadString(cmd))) { + MISC_HILOGE("Parcel read failed"); + return ERROR; + } std::string ret = GetVibratorParameter(vibratorId, cmd); reply.WriteString(ret); return NO_ERROR; @@ -207,31 +235,48 @@ int32_t MiscdeviceServiceStub::GetLightSupportIdPb(MessageParcel &data, MessageP int32_t MiscdeviceServiceStub::IsLightEffectSupportPb(MessageParcel &data, MessageParcel &reply) { - int32_t id = data.ReadInt32(); - std::string effect = data.ReadString(); + int32_t id; + std::string effect; + if ((!data.ReadInt32(id)) || (!data.ReadString(effect))) { + MISC_HILOGE("Parcel read failed"); + return ERROR; + } reply.WriteBool(IsLightEffectSupport(id, effect)); return NO_ERROR; } int32_t MiscdeviceServiceStub::LightPb(MessageParcel &data, MessageParcel &reply) { - int32_t id = data.ReadInt32(); - uint32_t brightness = data.ReadUint64(); - uint32_t timeOn = data.ReadUint32(); - uint32_t timeOff = data.ReadUint32(); + int32_t id; + uint64_t brightness; + uint32_t timeOn; + uint32_t timeOff; + if ((!data.ReadInt32(id)) || (!data.ReadUint64(brightness)) || + (!data.ReadUint32(timeOn)) || (!data.ReadUint32(timeOff))) { + MISC_HILOGE("Parcel read failed"); + return ERROR; + } return Light(id, brightness, timeOn, timeOff); } int32_t MiscdeviceServiceStub::PlayLightEffectPb(MessageParcel &data, MessageParcel &reply) { - int32_t id = data.ReadInt32(); - std::string type = data.ReadString(); + int32_t id; + std::string type; + if ((!data.ReadInt32(id)) || (!data.ReadString(type))) { + MISC_HILOGE("Parcel read failed"); + return ERROR; + } return PlayLightEffect(id, type); } int32_t MiscdeviceServiceStub::StopLightEffectPb(MessageParcel &data, MessageParcel &reply) { - int32_t id = data.ReadInt32(); + int32_t id; + if (!data.ReadInt32(id)) { + MISC_HILOGE("Parcel read failed"); + return ERROR; + } return StopLightEffect(id); }