diff --git a/frameworks/native/sensor/src/sensor_service_proxy.cpp b/frameworks/native/sensor/src/sensor_service_proxy.cpp index b0406b7a1ab6b066779538011780cffac1b1a41c..76be0c8cd338fd05cc1e39708a17a2827d895fbb 100755 --- a/frameworks/native/sensor/src/sensor_service_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_service_proxy.cpp @@ -177,7 +177,11 @@ std::vector SensorServiceProxy::GetSensorList() SEN_HILOGE("failed, ret:%{public}d", ret); return sensors; } - int32_t sensorCount = reply.ReadInt32(); + int32_t sensorCount; + if (!reply.ReadInt32(sensorCount)) { + SEN_HILOGE("Parcel read failed"); + return sensors; + } SEN_HILOGD("sensorCount:%{public}d", sensorCount); if (sensorCount > MAX_SENSOR_COUNT) { sensorCount = MAX_SENSOR_COUNT; diff --git a/utils/src/sensor.cpp b/utils/src/sensor.cpp index 3c0c2b7c38a25c65cab8881b580366f6b8d78722..69d5a5125575e16338362357dad6aa6d9b4a4ba6 100644 --- a/utils/src/sensor.cpp +++ b/utils/src/sensor.cpp @@ -241,19 +241,21 @@ std::unique_ptr Sensor::Unmarshalling(Parcel &parcel) bool Sensor::ReadFromParcel(Parcel &parcel) { - sensorId_ = parcel.ReadUint32(); - sensorTypeId_ = parcel.ReadUint32(); - sensorName_ = parcel.ReadString(); - vendorName_ = parcel.ReadString(); - firmwareVersion_ = parcel.ReadString(); - hardwareVersion_ = parcel.ReadString(); - power_ = parcel.ReadFloat(); - maxRange_ = parcel.ReadFloat(); - resolution_ = parcel.ReadFloat(); - flags_ = parcel.ReadUint32(); - fifoMaxEventCount_ = parcel.ReadInt32(); - minSamplePeriodNs_ = parcel.ReadInt64(); - maxSamplePeriodNs_ = parcel.ReadInt64(); + if ((!parcel.ReadUint32(sensorId_)) || + (!parcel.ReadUint32(sensorTypeId_)) || + (!parcel.ReadString(sensorName_)) || + (!parcel.ReadString(vendorName_)) || + (!parcel.ReadString(firmwareVersion_)) || + (!parcel.ReadString(hardwareVersion_)) || + (!parcel.ReadFloat(power_)) || + (!parcel.ReadFloat(maxRange_)) || + (!parcel.ReadFloat(resolution_)) || + (!parcel.ReadUint32(flags_)) || + (!parcel.ReadInt32(fifoMaxEventCount_)) || + (!parcel.ReadInt64(minSamplePeriodNs_)) || + (!parcel.ReadInt64(maxSamplePeriodNs_))) { + return false; + } return true; } } // namespace Sensors