From e1eabdc1dc481a9539c6c55a7ac3ceecd4585e98 Mon Sep 17 00:00:00 2001 From: chenming Date: Thu, 10 Mar 2022 14:54:38 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=96=B0=E5=A2=9Esize=E4=BF=9D=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenming --- frameworks/src/work_info.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frameworks/src/work_info.cpp b/frameworks/src/work_info.cpp index c4de581..6c76a5f 100644 --- a/frameworks/src/work_info.cpp +++ b/frameworks/src/work_info.cpp @@ -20,6 +20,7 @@ namespace OHOS { namespace WorkScheduler { const int INVALID_VALUE = -1; const int INVALID_TIME_VALUE = 0; +const size_t MAX_SIZE = 1024; WorkInfo::WorkInfo() { @@ -262,6 +263,10 @@ WorkInfo *WorkInfo::Unmarshalling(Parcel &parcel) read->abilityName_ = parcel.ReadString(); read->persisted_ = parcel.ReadBool(); size_t mapsize = parcel.ReadUint32(); + if (mapsize >= MAX_SIZE) { + return new WorkInfo(); + } + read->conditionMap_ = std::map>(); for (size_t i = 0; i < mapsize; i++) { int32_t key = parcel.ReadInt32(); -- Gitee From 181e2d689af6c523df398cb41290232df8152398 Mon Sep 17 00:00:00 2001 From: chenming Date: Thu, 10 Mar 2022 16:32:45 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E6=96=B0=E5=A2=9Edelete?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenming --- frameworks/src/work_info.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frameworks/src/work_info.cpp b/frameworks/src/work_info.cpp index 6c76a5f..5d225b7 100644 --- a/frameworks/src/work_info.cpp +++ b/frameworks/src/work_info.cpp @@ -264,6 +264,8 @@ WorkInfo *WorkInfo::Unmarshalling(Parcel &parcel) read->persisted_ = parcel.ReadBool(); size_t mapsize = parcel.ReadUint32(); if (mapsize >= MAX_SIZE) { + delete read; + read = nullptr; return new WorkInfo(); } -- Gitee From e612344c14692dc39ad872bba27a0e1b27d631c7 Mon Sep 17 00:00:00 2001 From: chenming Date: Thu, 10 Mar 2022 19:55:42 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E6=96=B0=E5=A2=9Esize=E4=BF=9D=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenming --- frameworks/include/work_info.h | 2 +- frameworks/src/work_info.cpp | 8 +++----- services/zidl/src/work_sched_service_proxy.cpp | 4 ++-- services/zidl/src/work_sched_service_stub.cpp | 6 +++--- services/zidl/src/work_scheduler_stub.cpp | 10 ++++++++-- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/frameworks/include/work_info.h b/frameworks/include/work_info.h index f1a773e..c21e02e 100644 --- a/frameworks/include/work_info.h +++ b/frameworks/include/work_info.h @@ -58,7 +58,7 @@ public: int32_t GetCycleCount(); std::shared_ptr>> GetConditionMap(); bool Marshalling(Parcel &parcel) const override; - static WorkInfo *Unmarshalling(Parcel &parcel); + static sptr Unmarshalling(Parcel &parcel); void Dump(std::string &result); std::string ParseToJsonStr(); bool ParseFromJson(const Json::Value value); diff --git a/frameworks/src/work_info.cpp b/frameworks/src/work_info.cpp index 5d225b7..f57d755 100644 --- a/frameworks/src/work_info.cpp +++ b/frameworks/src/work_info.cpp @@ -255,18 +255,16 @@ bool WorkInfo::Marshalling(Parcel &parcel) const return ret; } -WorkInfo *WorkInfo::Unmarshalling(Parcel &parcel) +sptr WorkInfo::Unmarshalling(Parcel &parcel) { - auto *read = new WorkInfo(); + sptr read = new (std::nothrow) WorkInfo(); read->workId_ = parcel.ReadInt32(); read->bundleName_ = parcel.ReadString(); read->abilityName_ = parcel.ReadString(); read->persisted_ = parcel.ReadBool(); size_t mapsize = parcel.ReadUint32(); if (mapsize >= MAX_SIZE) { - delete read; - read = nullptr; - return new WorkInfo(); + return nullptr; } read->conditionMap_ = std::map>(); diff --git a/services/zidl/src/work_sched_service_proxy.cpp b/services/zidl/src/work_sched_service_proxy.cpp index fc6e20c..177826e 100644 --- a/services/zidl/src/work_sched_service_proxy.cpp +++ b/services/zidl/src/work_sched_service_proxy.cpp @@ -180,7 +180,7 @@ std::list> WorkSchedServiceProxy::ObtainAllWorks(int32 READ_PARCEL_WITHOUT_RET(reply, Int32, worksize); WS_HILOGD("BUGOAWF WSSP ObtainAllWorks worksize from read parcel is: %{public}d", worksize); for (int32_t i = 0; i < worksize; i++) { - WorkInfo *workInfo = reply.ReadParcelable(); + sptr workInfo = reply.ReadStrongParcelable(); if (workInfo == nullptr) { continue; } @@ -210,7 +210,7 @@ std::shared_ptr WorkSchedServiceProxy::GetWorkStatus(int32_t &uid, int WS_HILOGE("%{pulbic}s SendRequest is failed, err code: %{public}d", __func__, ret); return nullptr; } - WorkInfo *workInfo = reply.ReadParcelable(); + sptr workInfo = reply.ReadStrongParcelable(); if (workInfo == nullptr) { return nullptr; } diff --git a/services/zidl/src/work_sched_service_stub.cpp b/services/zidl/src/work_sched_service_stub.cpp index 80a45d1..c8ba2df 100644 --- a/services/zidl/src/work_sched_service_stub.cpp +++ b/services/zidl/src/work_sched_service_stub.cpp @@ -87,7 +87,7 @@ int WorkSchedServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Me int32_t WorkSchedServiceStub::StartWorkStub(MessageParcel& data) { - WorkInfo* pw = data.ReadParcelable(); + sptr pw = data.ReadStrongParcelable(); WorkInfo& workInfo = *pw; if (!StartWork(workInfo)) { WS_HILOGE("StartWork failed"); @@ -98,7 +98,7 @@ int32_t WorkSchedServiceStub::StartWorkStub(MessageParcel& data) int32_t WorkSchedServiceStub::StopWorkStub(MessageParcel& data) { - WorkInfo* pw = data.ReadParcelable(); + sptr pw = data.ReadStrongParcelable(); WorkInfo& workInfo = *pw; if (!StopWork(workInfo)) { return E_STOP_WORK_FAILED; @@ -108,7 +108,7 @@ int32_t WorkSchedServiceStub::StopWorkStub(MessageParcel& data) int32_t WorkSchedServiceStub::StopAndCancelWorkStub(MessageParcel& data) { - WorkInfo* pw = data.ReadParcelable(); + sptr pw = data.ReadStrongParcelable(); WorkInfo& workInfo = *pw; if (!StopAndCancelWork(workInfo)) { return E_STOP_AND_CANCEL_WORK_FAILED; diff --git a/services/zidl/src/work_scheduler_stub.cpp b/services/zidl/src/work_scheduler_stub.cpp index c316a0c..6dc0951 100644 --- a/services/zidl/src/work_scheduler_stub.cpp +++ b/services/zidl/src/work_scheduler_stub.cpp @@ -27,12 +27,18 @@ int WorkSchedulerStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Messa } switch (code) { case COMMAND_ON_WORK_START: { - WorkInfo* workInfo = data.ReadParcelable(); + sptr workInfo = reply.ReadStrongParcelable(); + if (workInfo == nullptr) { + return ERR_TRANSACTION_FAILED; + } OnWorkStart(*workInfo); return ERR_NONE; } case COMMAND_ON_WORK_STOP: { - WorkInfo* workInfo = data.ReadParcelable(); + sptr workInfo = reply.ReadStrongParcelable(); + if (workInfo == nullptr) { + return ERR_TRANSACTION_FAILED; + } OnWorkStop(*workInfo); return ERR_NONE; } -- Gitee From 53c77ac3d864ef67c6b0e3381a18e90b543a7640 Mon Sep 17 00:00:00 2001 From: chenming Date: Thu, 10 Mar 2022 20:20:51 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=88=A4=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenming --- frameworks/src/work_info.cpp | 3 +++ services/zidl/src/work_sched_service_stub.cpp | 27 ++++++++++++------- services/zidl/src/work_scheduler_stub.cpp | 2 ++ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/frameworks/src/work_info.cpp b/frameworks/src/work_info.cpp index f57d755..8de1d60 100644 --- a/frameworks/src/work_info.cpp +++ b/frameworks/src/work_info.cpp @@ -258,6 +258,9 @@ bool WorkInfo::Marshalling(Parcel &parcel) const sptr WorkInfo::Unmarshalling(Parcel &parcel) { sptr read = new (std::nothrow) WorkInfo(); + if (read == nullptr) { + return nullptr; + } read->workId_ = parcel.ReadInt32(); read->bundleName_ = parcel.ReadString(); read->abilityName_ = parcel.ReadString(); diff --git a/services/zidl/src/work_sched_service_stub.cpp b/services/zidl/src/work_sched_service_stub.cpp index c8ba2df..2dd2d7a 100644 --- a/services/zidl/src/work_sched_service_stub.cpp +++ b/services/zidl/src/work_sched_service_stub.cpp @@ -87,9 +87,12 @@ int WorkSchedServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Me int32_t WorkSchedServiceStub::StartWorkStub(MessageParcel& data) { - sptr pw = data.ReadStrongParcelable(); - WorkInfo& workInfo = *pw; - if (!StartWork(workInfo)) { + sptr workInfo = data.ReadStrongParcelable(); + if (workInfo == nullptr) { + WS_HILOGD("workInfo is nullptr"); + return E_START_WORK_FAILED; + } + if (!StartWork(*workInfo)) { WS_HILOGE("StartWork failed"); return E_START_WORK_FAILED; } @@ -98,9 +101,12 @@ int32_t WorkSchedServiceStub::StartWorkStub(MessageParcel& data) int32_t WorkSchedServiceStub::StopWorkStub(MessageParcel& data) { - sptr pw = data.ReadStrongParcelable(); - WorkInfo& workInfo = *pw; - if (!StopWork(workInfo)) { + sptr workInfo = data.ReadStrongParcelable(); + if (workInfo == nullptr) { + WS_HILOGD("workInfo is nullptr"); + return E_START_WORK_FAILED; + } + if (!StopWork(*workInfo)) { return E_STOP_WORK_FAILED; } return ERR_OK; @@ -108,9 +114,12 @@ int32_t WorkSchedServiceStub::StopWorkStub(MessageParcel& data) int32_t WorkSchedServiceStub::StopAndCancelWorkStub(MessageParcel& data) { - sptr pw = data.ReadStrongParcelable(); - WorkInfo& workInfo = *pw; - if (!StopAndCancelWork(workInfo)) { + sptr workInfo = data.ReadStrongParcelable(); + if (workInfo == nullptr) { + WS_HILOGD("workInfo is nullptr"); + return E_START_WORK_FAILED; + } + if (!StopAndCancelWork(*workInfo)) { return E_STOP_AND_CANCEL_WORK_FAILED; } return ERR_OK; diff --git a/services/zidl/src/work_scheduler_stub.cpp b/services/zidl/src/work_scheduler_stub.cpp index 6dc0951..2d13035 100644 --- a/services/zidl/src/work_scheduler_stub.cpp +++ b/services/zidl/src/work_scheduler_stub.cpp @@ -29,6 +29,7 @@ int WorkSchedulerStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Messa case COMMAND_ON_WORK_START: { sptr workInfo = reply.ReadStrongParcelable(); if (workInfo == nullptr) { + WS_HILOGE("workInfo is nullptr"); return ERR_TRANSACTION_FAILED; } OnWorkStart(*workInfo); @@ -37,6 +38,7 @@ int WorkSchedulerStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Messa case COMMAND_ON_WORK_STOP: { sptr workInfo = reply.ReadStrongParcelable(); if (workInfo == nullptr) { + WS_HILOGE("workInfo is nullptr"); return ERR_TRANSACTION_FAILED; } OnWorkStop(*workInfo); -- Gitee From 67d89367f8795bbbc886a3b756218711d3702b4d Mon Sep 17 00:00:00 2001 From: chenming Date: Thu, 10 Mar 2022 20:24:07 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=80=BC=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenming --- services/zidl/src/work_sched_service_stub.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/zidl/src/work_sched_service_stub.cpp b/services/zidl/src/work_sched_service_stub.cpp index 2dd2d7a..85538ec 100644 --- a/services/zidl/src/work_sched_service_stub.cpp +++ b/services/zidl/src/work_sched_service_stub.cpp @@ -104,7 +104,7 @@ int32_t WorkSchedServiceStub::StopWorkStub(MessageParcel& data) sptr workInfo = data.ReadStrongParcelable(); if (workInfo == nullptr) { WS_HILOGD("workInfo is nullptr"); - return E_START_WORK_FAILED; + return E_STOP_WORK_FAILED; } if (!StopWork(*workInfo)) { return E_STOP_WORK_FAILED; @@ -117,7 +117,7 @@ int32_t WorkSchedServiceStub::StopAndCancelWorkStub(MessageParcel& data) sptr workInfo = data.ReadStrongParcelable(); if (workInfo == nullptr) { WS_HILOGD("workInfo is nullptr"); - return E_START_WORK_FAILED; + return E_STOP_AND_CANCEL_WORK_FAILED; } if (!StopAndCancelWork(*workInfo)) { return E_STOP_AND_CANCEL_WORK_FAILED; -- Gitee From 2a7c5f0914bdaa3e079284841c864e7aefdb48f1 Mon Sep 17 00:00:00 2001 From: chenming Date: Thu, 10 Mar 2022 20:55:02 +0800 Subject: [PATCH 6/6] bugfix Signed-off-by: chenming --- frameworks/src/work_info.cpp | 2 ++ services/zidl/src/work_scheduler_stub.cpp | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/frameworks/src/work_info.cpp b/frameworks/src/work_info.cpp index 8de1d60..db4145f 100644 --- a/frameworks/src/work_info.cpp +++ b/frameworks/src/work_info.cpp @@ -259,6 +259,7 @@ sptr WorkInfo::Unmarshalling(Parcel &parcel) { sptr read = new (std::nothrow) WorkInfo(); if (read == nullptr) { + WS_HILOGD("read is nullptr."); return nullptr; } read->workId_ = parcel.ReadInt32(); @@ -267,6 +268,7 @@ sptr WorkInfo::Unmarshalling(Parcel &parcel) read->persisted_ = parcel.ReadBool(); size_t mapsize = parcel.ReadUint32(); if (mapsize >= MAX_SIZE) { + WS_HILOGD("mapsize is too big."); return nullptr; } diff --git a/services/zidl/src/work_scheduler_stub.cpp b/services/zidl/src/work_scheduler_stub.cpp index 2d13035..b2dac7c 100644 --- a/services/zidl/src/work_scheduler_stub.cpp +++ b/services/zidl/src/work_scheduler_stub.cpp @@ -27,7 +27,7 @@ int WorkSchedulerStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Messa } switch (code) { case COMMAND_ON_WORK_START: { - sptr workInfo = reply.ReadStrongParcelable(); + sptr workInfo = data.ReadStrongParcelable(); if (workInfo == nullptr) { WS_HILOGE("workInfo is nullptr"); return ERR_TRANSACTION_FAILED; @@ -36,7 +36,7 @@ int WorkSchedulerStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Messa return ERR_NONE; } case COMMAND_ON_WORK_STOP: { - sptr workInfo = reply.ReadStrongParcelable(); + sptr workInfo = data.ReadStrongParcelable(); if (workInfo == nullptr) { WS_HILOGE("workInfo is nullptr"); return ERR_TRANSACTION_FAILED; -- Gitee